Skip to content

Cannot correctly infer the condition type of a generic function #46443

Closed
@Grapedge

Description

@Grapedge

Bug Report

typescript: 4.4.3

💻 Code

interface Config {
  field: string
}

type GetFieldType<T extends Config = Config> = T extends Config
  ? true
  : false

const test1: GetFieldType = true // => ok

function testFunc<T extends Config>() {
  const test2: GetFieldType<T> = true // ts 2322
  const test3: GetFieldType<T> = false // ts 2322
}

test1 works well.
But in the generic function, T inherits from Config, but ts cannot infer the type

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions