Skip to content

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

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
Grapedge opened this issue Oct 20, 2021 · 3 comments
Closed

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

Grapedge opened this issue Oct 20, 2021 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Grapedge
Copy link

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

@MartinJohns
Copy link
Contributor

Same as #46155. test1 works because the type of T is known to be Config. test2 and test3 don't work, because the type of T is not yet known, so resolving of the conditional is deferred.

@jcalz
Copy link
Contributor

jcalz commented Oct 20, 2021

Duplicate of #23132 I think

@DanielRosenwasser DanielRosenwasser added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 4, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants