从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
Extract
/**
* Extract from T those types that are assignable to U
* 提取来自U中的属性到T中
*/
type Extract
Omit
/**
* Construct a type with the properties of T except for those in type K.
* 构造一个 type 用T中的属性(排除掉来自K )
*/
type Omit
NonNullable
/**
* Exclude null and undefined from T
*/
type NonNullable
Parameters
/**
* Obtain the parameters of a function type in a tuple
*/
type Parameters
ConstructorParameters
/**
* Obtain the parameters of a constructor function type in a tuple
*/
type ConstructorParameters
ReturnType
/**
* Obtain the return type of a function type
*/
type ReturnType
InstanceType
/**
* Obtain the return type of a constructor function type
*/
type InstanceType
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
�
�
�
