//#region src/types/index.d.ts /** 允许为 null 的类型 */ type Nullable = T | null; /** 允许为 undefined 的类型 */ type Optional = T | undefined; /** 允许为 null 或 undefined 的类型 */ type Maybe = T | null | undefined; /** 获取对象所有 value 的联合类型 */ type ValueOf = T[keyof T]; /** 递归地将对象所有属性变为可选 */ type DeepPartial = { [P in keyof T]?: DeepPartial }; /** 原始类型的联合 */ type Primitive = string | number | boolean | bigint | symbol | null | undefined; /** 合并两个类型,U 的属性会覆盖 T 的同名属性 */ type Merge = Omit & U; /** 从对象类型 T 中排除指定属性 K */ type Without = Omit; /** 只保留对象类型 T 的指定属性 K */ type WithOnly = Pick; /** 递归地将对象所有属性变为只读 */ type DeepReadonly = { readonly [P in keyof T]: DeepReadonly }; /** 递归地将对象所有属性变为可选 */ type DeepOptional = { [P in keyof T]?: DeepOptional }; /** 递归地将对象所有属性变为必选 */ type DeepRequired = { [P in keyof T]-?: DeepRequired }; /** 递归地将对象所有属性变为可变(非 readonly) */ type DeepMutable = { -readonly [P in keyof T]: DeepMutable }; /** 获取函数参数类型组成的元组 */ type ArgumentsType any> = T extends ((...args: infer A) => any) ? A : never; /** 获取函数返回值类型 */ type ReturnTypeOf any> = T extends ((...args: any) => infer R) ? R : any; /** 将联合类型转为交叉类型 */ type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; /** 判断类型是否为 any */ type IsAny = 0 extends 1 & T ? true : false; //#endregion export { ArgumentsType, DeepMutable, DeepOptional, DeepPartial, DeepReadonly, DeepRequired, IsAny, Maybe, Merge, Nullable, Optional, Primitive, ReturnTypeOf, UnionToIntersection, ValueOf, WithOnly, Without };