From 2aba29fc32b21cd9f56ea8510c37772735ebcadf Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 9 Feb 2018 14:22:46 -0800 Subject: [PATCH] Add Exclude, Extract, NonNullable, ReturnType, and InstanceType types --- src/lib/es5.d.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 707f749e365..0f773e78786 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1338,6 +1338,31 @@ type Record = { [P in K]: T; }; +/** + * Exclude from T those types that are assignable to U + */ +type Exclude = T extends U ? never : T; + +/** + * Extract from T those types that are assignable to U + */ +type Extract = T extends U ? T : never; + +/** + * Exclude null and undefined from T + */ +type NonNullable = T extends null | undefined ? never : T; + +/** + * Obtain the return type of a function type + */ +type ReturnType any> = T extends (...args: any[]) => infer R ? R : any; + +/** + * Obtain the return type of a constructor function type + */ +type InstanceType any> = T extends new (...args: any[]) => infer R ? R : any; + /** * Marker for contextual 'this' type */