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
#30708 looks similarish. However, it is my understanding that nested union types will not be expanded when compared with a conditional. So [boolean] extends [true] would not be expanded to [true | false] extends [true] and would not be expanded to [true] | [false] extends [true].
I‘d expect this example to pass since we are explicitly putting the union (in this case boolean) under the conditional’s test.
The text was updated successfully, but these errors were encountered:
This is the right behaviour because MyType is not a distributive conditional type; boolean extends true will always be false as the union is viewed atomically.
It needs to be written as:
typeDist<T>=Textendstrue ? number : string;typeMyType<OptionsextendsMyOptions>=Dist<Options["foo"]>;
Yep, this is what the documentation means when it says distribution happens over a “naked type parameter”. It’s also why you can easily disable distribution by writing the type as [T] extends [U] ? ...
TypeScript Version: 3.5.1
Search Terms: boolean, property
Code
Expected behavior: This example should pass,
MyType<MyOptions>
should benumber | string
.Actual behavior: This example fails,
MyType<MyOptions>
isfalse
.Playground Link: TypeScript Playground
Related Issues:
#30708 looks similarish. However, it is my understanding that nested union types will not be expanded when compared with a conditional. So
[boolean] extends [true]
would not be expanded to[true | false] extends [true]
and would not be expanded to[true] | [false] extends [true]
.I‘d expect this example to pass since we are explicitly putting the union (in this case
boolean
) under the conditional’s test.The text was updated successfully, but these errors were encountered: