-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Conditional types don't work with passed never type #23022
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
I believe this is working as intended: |
|
not really. a type is distributed if it has a naked type parameter in the condition close. so type inline = number | string extends string ? true : false; // false
type deferred<T> = T extends string ? true : false;
type d = deferred<number | string>; // boolean The rational here that using a type parameter in the condition position is like a function on the input, and is expected to distribute, where as an actual union type is mean to be used as is. |
I understood, this is not inlining. A passed union type is not determined as its exact union type yet. It also can be a subtype. |
A workaround: type C<T, U> = [T] extends [never] ? 1 : T extends U ? 1 : 0;
type a = C<never, void>; // 1
type b = C<never, never>; // 1
type c = C<boolean, true>; // 0 | 1 |
cc @ahejlsberg
TypeScript Version: 2.7.0-dev.20180330
Search Terms:
Code
Expected behavior:
A
andB
aretrue
.Actual behavior:
A
istrue
,B
isnever
.Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: