Ts 泛型工具类
2024-09-22 本文已影响0人
逗婆苍穹
- Pick Omit
type O = { a: string; b: number };
type A = Pick<O, "a">; // { a: string }
type B = Omit<O, "a">; // { b:number }
type O = { a: string; b: number };
type A = Exclude<string | number, string>; // number
type B = Extract<string | number, string>; // string
Partial<T> // 可选
Required<T> // 必填
Readonly<T> // 只读
type A = Record<string | number, any>;
// 参数1:string | number | symbol 组成的单个或联合类型,参数2 :任意类型
// keyof any = string | number | symbol
// A = {
// [x: string]: any;
// [x: number]: any;
// [x: symbol]: any;
// }
- 更多详细内容参考
https://mp.weixin.qq.com/s?__biz=MjM5MDA2MTI1MA==&mid=2649133378&idx=1&sn=64c59bb788fa4ba7e1b1a87f495b1a50&chksm=be58b6ef892f3ff9b354c510ef2228a4409010fd4aea1a4fab0e9d524a5829627bfc38cadaf2&scene=27