You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What motivated me to report this is the fact that this construct can make Typescript ignore type constraints :
typeA<Textendsstring>={[TKeyinT]: string};typeB<Textendsstring>=T;typeC<T>=TextendsB<infer U> ? A<U> : never;typeD=C<boolean>;// Evaluated as A<boolean>, which shouldn't be valid
it also seems inconsistent to me since this code works as expected :
type B<T extends string> = {a: T}; type C<T> = T extends B<infer U> ? A<U> : never; type D = C<{a: boolean}>; // never, as expected
I don't know if it can be a problem in real world code though... I can't think of any use-case where an "Identity" type such as B would be useful in a conditional type...
EDIT
Please ignore the second part of my comment, the result is exactly the same (A<boolean>, not never). This had nothing to do with the fact that B is a "identity" type. Sorry about that.
TypeScript Version:
2.8.0-dev.201802213
Search Terms:
conditional, inference, constraint
Code
Expected behavior:
Test2
has typenever
Actual behavior:
Test2
has type42
, even though typescript correctly infers thatU
must be astring
in the conditional true branch.Playground Link:
Related issues:
#21937 #21631
The text was updated successfully, but these errors were encountered: