Generic type sometimes returns never instead of actual template parameter type
See original GitHub issueTypeScript Version: 3.6+
Search Terms: enum, extends, never, template parameters
Code
enum FL4 { Absurd, False, True, Unknown }
type Classify< Left, Right > = Left extends Right
? Right extends Left
? [ Left , '==', Right ]
: [ Left , '<:', Right ]
: Right extends Left
? [ Left, ':>', Right ]
: [ Left , '!=', Right ]
type Absurd_is_never_wtf = Assert<
Classify< FL4.Absurd, 0 >,
[ never, '<:', 0 ]
>
type One_is_never_wtf = Assert<
Classify< FL4.Absurd, 1 >,
[ FL4.Absurd, ':>', never ]
>
type Absurd_is_Absurd = Assert<
Classify< FL4.Absurd, 0 >,
[ FL4.Absurd, '==', 0 ]
>
type One_is_One = Assert<
Classify< FL4.Absurd, 1 >,
[ FL4.Absurd, ':>', 1 ]
>
```
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Typescript Function with Generic Return Type - Stack Overflow
To reiterate: when you have a generic function, the generic type parameters are specified by the caller, not by the implementer.
Read more >Handbook - Unions and Intersection Types - TypeScript
How to use unions and intersection types in TypeScript. ... let you compose or combine existing types instead of creating them from scratch....
Read more >Function template - cppreference.com
Two function templates with the same return type and the same parameter list are distinct and can be distinguished with explicit template argument...
Read more >Effective Dart: Design
A boolean name should never sound like a command to tell the object to do something, ... At compile time, the compiler looks...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
The wildcard can be used as the type of a parameter, field, or local variable and sometimes as a return type. We can't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We encountered this issue over at socketio/socket.io#3833. Here’s another minimized bug reproduction:
So then this is a duplicate/related to #21998, I think. Why can’t we have the intersection of an enum and the wider literal it comes from just be the enum? Especially for string enums, which doesn’t have the bitflag craziness to deal with?