Skip to content

Commit 7cb073f

Browse files
authored
feat: "Extends" TypeScript util type (#1394)
TypeScript util type "Extends" resolves #1393
1 parent 235c3a2 commit 7cb073f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

packages/utils/src/TypeUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Util type to create a "subtype" of T. Useful for creating subsets of union
3+
* types.
4+
*
5+
* e.g.
6+
* declare type Direction = 'north' | 'south' | 'east' | 'west'
7+
*
8+
* // This works
9+
* type Down = Extends<Direction, 'south'> // 'south'
10+
*
11+
* // Compiler will complain
12+
* type NotDirection = Extends<Direction, 'blah'>
13+
*/
14+
export type Extends<T, U extends T> = U extends T ? U : never;
15+
116
/**
217
* Util type to extract the value from an object.
318
*

0 commit comments

Comments
 (0)