-
Notifications
You must be signed in to change notification settings - Fork 31
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
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. |
packages/utils/src/TypeUtils.ts
Outdated
* // Compiler will complain | ||
* type NotDirection = Subset<Direction, 'blah'> | ||
*/ | ||
export type Extends<T, U extends T> = U; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. Fixed
TypeScript util type "Extends"
resolves #1393