-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Generic conditional type T extends never ? 'yes' : 'no' resolves to never when T is never. #31751
Comments
This is the expected behavior, If you disable distribution for type MakesSense = never extends never ? 'yes' : 'no' // Resolves to 'yes'
type ExtendsNever<T> = [T] extends [never] ? 'yes' : 'no'
type MakesSenseToo = ExtendsNever<{}> // Resolves to 'no'
type Huh = ExtendsNever<never> // is yes |
Thanks for the clarification. I should really get around to reading my Homotopy Type Theory book. |
Why is I understand that |
@fatcerberus; Discussed in #27418 |
I've got here because I was unable to understand why
It means that when |
but type-challenges-01097 ,its last test example thinks Never is not Union Type |
@ZhanghaoH you can think of the type challenge problem not as "isUnion" but as "isDistributiveUnion" or "isUnionOfMoreThenOneElement". Unions of 0 elements, 1 element, and 1+ elements behave differently in TS, and the problem is about detecting the third, non-singular case |
I see...thanks for your reply ! |
TypeScript Version: 3.6.0-dev.20190603
Search Terms:
never, extends, generic, conditional type
Code
Expected behavior:
Huh should resolve to 'yes', as MakesSense does.
Actual behavior:
Huh resolves to never.
For another variant, you can change ExtendsNever to
and ExtendsNever still resolves to never.
Playground Link:
Here
Related Issues:
None
The text was updated successfully, but these errors were encountered: