美文网首页
Ts 泛型工具类

Ts 泛型工具类

作者: 逗婆苍穹 | 来源:发表于2024-09-22 10:53 被阅读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

相关文章

网友评论

      本文标题:Ts 泛型工具类

      本文链接:https://www.haomeiwen.com/subject/nwitrjtx.html