JavaScript/typescript/Record
来自康健生活
< JavaScript | typescript
引言
将 K 中所有的属性的值转化为 T 类型。
type Record<K extends keyof any, T> = { [P in K]: T; };
示例
interface Engineer{
name: string;
age: number;
profession?: string;
interest?: string[];
}
type BackendEngineer = Record<'name' | 'age', string>;
// 等价于
/*
type BackendEngineer === {
name: string;
age: string;
profession?: string;
interest?: string[];
}
*/
No categories