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
typeIsNever<T>=(Textendsnever
? true
: false)letfoo: IsNever<1>// falseletbar: IsNever<never>// never
But since it always returning false or never is complicated to compound more complex types, for example:
typeArrayHasLessThanThreeElements<T>=(IsNever<Extract<'2',keyofT>>)leta: ArrayHasLessThanThreeElements<[1,2,3]>// falseletb: ArrayHasLessThanThreeElements<[1,2]>// never, but the expected type is "true"
Use Cases
It is useful when you need to compound types and use something like T extends never.
Since if T is never the truthy clausure isn't run, it's very complicated to compound types at this case.
Examples
Let's say that we have the new utility type IsNever from TS:
Search Terms
never, distributive conditional type
Suggestion
As described at this issue, this behaviour is the expected:
But since it always returning
false
ornever
is complicated to compound more complex types, for example:Use Cases
It is useful when you need to compound types and use something like
T extends never
.Since if T is
never
the truthy clausure isn't run, it's very complicated to compound types at this case.Examples
Let's say that we have the new utility type
IsNever
from TS:The text was updated successfully, but these errors were encountered: