-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Conditional type doesn't go to true or false branch. #48243
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
Comments
Resolving of conditional types involving unbound generic type arguments is deferred. At that point the compiler doesn't know what |
@MartinJohns thanks for clarification, but i still don't understand. why it doesn't know what result of conditional type if i'm telling it that T will extend Record<string, unknown> |
|
@MartinJohns playground but why this works ? |
Conditional types are not necessarily linear (meaning that they have predictable behavior between |
@RyanCavanaugh okey, but why [T] extends [never] and T extends never produce different results (you can see the example above) ? |
@alexeymolchan https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
@fatcerberus as i see from playground where |
@MartinJohns mapped type like this |
How would the compiler know what the final type will look like without knowing what type |
To be clear, generics in TS don't work like C++ templates. The compiler only looks at the body of a generic once and tries to determine if it will work for all possible combinations of type parameters, but these checks are necessarily conservative because it would be prohibitively expensive and/or complex to do otherwise. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
generic conditional types
already checked https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs and #31751
π Version & Regression Information
3.9.7 / 4.6.2
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
properties from intersection are not accessible (conditional type doesn't resolve as true / false branch)
π Expected behavior
conditional type should go to false branch. correct my please if i'm wrong
Thanks in advance.
The text was updated successfully, but these errors were encountered: