Skip to content

Regression in 2.9+: conditional type inferring empty object #24784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jamesknelson opened this issue Jun 8, 2018 · 1 comment
Closed

Regression in 2.9+: conditional type inferring empty object #24784

jamesknelson opened this issue Jun 8, 2018 · 1 comment
Labels
Bug A bug in TypeScript

Comments

@jamesknelson
Copy link

TypeScript Version: 3.0.0-dev.20180607

Search Terms:

conditional inference empty infer extends mapped

Code

type Combine<C, Prop extends string> = {
  [Key in keyof C]: (
    C[Key] extends { [X in Prop]: infer Just } ? Just :
    C[Key] extends { [X in Prop]?: infer Maybe } ? (Maybe | undefined) :
    undefined
  )
}

type Test = {
  x: {
    test?: boolean,
  },
  y: {
    test?: boolean,
  },
}

type Combined = Combine<Test, 'test'>

let combined: Combined

// Type '{}' is not assignable to type 'boolean'.
let flag: boolean = combined.x

Expected behavior:

Should compile, as the type of combined.x should be boolean.

Actual behavior:

In 2.9+, fails with "Type '{}' is not assignable to type 'boolean'."

In 2.8.1, compiles without error.

Playground Link:

Playground link

Related Issues:

@RyanCavanaugh
Copy link
Member

This got fixed in 3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants