feat: "Extends" TypeScript util type#1394
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1394 +/- ##
=======================================
Coverage 45.59% 45.59%
=======================================
Files 506 506
Lines 34976 34976
Branches 8738 8738
=======================================
Hits 15947 15947
Misses 18978 18978
Partials 51 51
Flags with carried forward coverage won't be shown. Click here to find out more. |
| * // Compiler will complain | ||
| * type NotDirection = Subset<Direction, 'blah'> | ||
| */ | ||
| export type Extends<T, U extends T> = U; |
There was a problem hiding this comment.
What's the use case you're trying to solve with this? Would the built-in Extract utility work?
There was a problem hiding this comment.
Extract allows non-existent literal types but produces a never. Extends will actually complain if you pass an invalid type
There was a problem hiding this comment.
Just complains in different spots. Looks like w/ this Extends it complains at the type definition and not usages. With Extract complains at usages b/c it is never.
If you wanted best of both worlds you could use type Extends<T, U extends T> = U extends T ? U : never
I'm guessing this is aimed at union types mostly since interfaces can just use extends keyword in their definition
There was a problem hiding this comment.
Good suggestion. Fixed
TypeScript util type "Extends"
resolves #1393