Files
Snippets/src/ts/handle.ts
2024-06-11 08:58:38 +08:00

17 lines
341 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 };