17 lines
341 B
TypeScript
17 lines
341 B
TypeScript
// keyof 操作符,遍历对象的key
|
||
export type keys<T> = keyof T;
|
||
|
||
const a = { a: 1, b: 2, c: 3 };
|
||
|
||
// typeof 提取类型
|
||
export type Ta = keys<typeof a>;
|
||
|
||
// Omit 去除某一项
|
||
export type Ta2 = Omit<typeof a, "b">;
|
||
|
||
// Pick 选择某一项
|
||
export type Ta3 = Pick<typeof a, "c">;
|
||
|
||
// & 添加
|
||
export type Ta4 = Ta3 & { d: string };
|