从typescript中lib.d.ts中找到了源码看了常用的高级工具类型。
从英文注释中看出来它的用途。在日常工作中可能会经常用到。

Record

/*
Construct a type with a set of properties K of type T
*/
Record = {
[P in K]: T;
};

  • demo ```javascript type wordsGroup = ‘a’ | ‘b’ | ‘c’; interface IWordInfo { name:string, age:number, }

type IWord = Record;

const animalsInfo:IWord = { a:{ name:’a’, age:1 }, b:{ name:’b’, age:2 }, c:{ name:’c’, age:3 } } ```

Exclude

/**
* Exclude from T those types that are assignable to U
* 从T中排出来自U的属性
*/
type Exclude = T extends U ? never : T;

Extract

/**
* Extract from T those types that are assignable to U
* 提取来自U中的属性到T中
*/
type Extract = T extends U ? T : never;

Omit

/**
* Construct a type with the properties of T except for those in type K.
* 构造一个 type 用T中的属性(排除掉来自K )
*/
type Omit = Pick>;

NonNullable

/**
* Exclude null and undefined from T
*/
type NonNullable = T extends null | undefined ? never : T;

Parameters

/**
* Obtain the parameters of a function type in a tuple
*/
type Parameters any> = T extends (…args: infer P) => any ? P : never;

ConstructorParameters

/**
* Obtain the parameters of a constructor function type in a tuple
*/
type ConstructorParameters any> = T extends new (…args: infer P) => any ? P : never;

ReturnType

/**
* Obtain the return type of a function type
*/
type ReturnType any> = T extends (…args: any) => infer R ? R : any;

InstanceType

/**
* Obtain the return type of a constructor function type
*/
type InstanceType any> = T extends new (…args: any) => infer R ? R : any;

Uppercase

/**
* Convert string literal type to uppercase
*/
type Uppercase = intrinsic;

Lowercase

/**
* Convert string literal type to lowercase
*/
type Lowercase = intrinsic;

Capitalize

/**
* Convert first character of string literal type to uppercase
*/
type Capitalize = intrinsic;

Uncapitalize

/**
* Convert first character of string literal type to lowercase
*/
type Uncapitalize = intrinsic;

ThisType

/**
* Marker for contextual ‘this’ type
*/
interface ThisType { }
�
�

�