Skip to content

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

Closed
@jamesknelson

Description

@jamesknelson

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions