Skip to content
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

Merged
merged 3 commits into from
Jul 3, 2023

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Jul 3, 2023

TypeScript util type "Extends"

resolves #1393

@bmingles bmingles requested a review from mattrunyon July 3, 2023 16:47
@codecov
Copy link

codecov bot commented Jul 3, 2023

Codecov Report

Merging #1394 (39b203e) into main (235c3a2) will not change coverage.
The diff coverage is n/a.

@@           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           
Flag Coverage Δ
unit 45.59% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

packages/utils/src/TypeUtils.ts Outdated Show resolved Hide resolved
* // Compiler will complain
* type NotDirection = Subset<Direction, 'blah'>
*/
export type Extends<T, U extends T> = U;
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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

https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCiIbAHYBMDOAPACoA0cAqnKFnvnMQHxwC8lA3AFCe7ADGAGwCGUVEhRwAIgEtRfGNIjZWcAOTZoMABaq4AHzX4IAV226Dq4EPwxzagO7Abq7gHpXcPhAC2YYdOx8TnFUAEEVDFoCQhk5BSVyVSNTLRBVRjcPXAgnbFV4L19-bGDkVAAhCMwoIXkY2X547ETk7TSMzgAzY2x5RWVvRAAxHr4ACiEALjhQ8gAjafKASmmANwhpXDgAb044fbghADoA3hAAeU6xgCJWrWulrgO4OZO8UEubu4euAF9OIA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Fixed

@bmingles bmingles requested a review from mattrunyon July 3, 2023 17:32
@bmingles bmingles merged commit 7cb073f into deephaven:main Jul 3, 2023
@bmingles bmingles deleted the 1393-util-type-extends branch July 3, 2023 19:19
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript utility type: Extends
2 participants