Skip to content

Commit 2aba29f

Browse files
committed
Add Exclude, Extract, NonNullable, ReturnType, and InstanceType types
1 parent 6dd88b3 commit 2aba29f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/lib/es5.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,31 @@ type Record<K extends string, T> = {
13381338
[P in K]: T;
13391339
};
13401340

1341+
/**
1342+
* Exclude from T those types that are assignable to U
1343+
*/
1344+
type Exclude<T, U> = T extends U ? never : T;
1345+
1346+
/**
1347+
* Extract from T those types that are assignable to U
1348+
*/
1349+
type Extract<T, U> = T extends U ? T : never;
1350+
1351+
/**
1352+
* Exclude null and undefined from T
1353+
*/
1354+
type NonNullable<T> = T extends null | undefined ? never : T;
1355+
1356+
/**
1357+
* Obtain the return type of a function type
1358+
*/
1359+
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
1360+
1361+
/**
1362+
* Obtain the return type of a constructor function type
1363+
*/
1364+
type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => infer R ? R : any;
1365+
13411366
/**
13421367
* Marker for contextual 'this' type
13431368
*/

0 commit comments

Comments
 (0)