Skip to content

Commit

Permalink
feat: "Extends" TypeScript util type (#1394)
Browse files Browse the repository at this point in the history
TypeScript util type "Extends"

resolves #1393
  • Loading branch information
bmingles authored Jul 3, 2023
1 parent 235c3a2 commit 7cb073f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/utils/src/TypeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Util type to create a "subtype" of T. Useful for creating subsets of union
* types.
*
* e.g.
* declare type Direction = 'north' | 'south' | 'east' | 'west'
*
* // This works
* type Down = Extends<Direction, 'south'> // 'south'
*
* // Compiler will complain
* type NotDirection = Extends<Direction, 'blah'>
*/
export type Extends<T, U extends T> = U extends T ? U : never;

/**
* Util type to extract the value from an object.
*
Expand Down

0 comments on commit 7cb073f

Please sign in to comment.