waleiwalei
waleiwalei
> 保留参数名 > > ```ts > type FirstAsArray = T extends [...infer A, infer B] ? A extends [] ? T : FirstAsArray : [] > type Curry< > F...
```ts type Shift = T extends [infer Rirst, ...infer Arr] ? Arr : [] // 测试用例 type S0 = Shift type S1 = Shift ``
```ts type Foo = { a: number; b?: string; c: boolean; } type Simplify = { [P in keyof T]: T[P] } type SetOptional = Partial & Pick type SomeOptional...
type A = Partial & Pick type SetOptional = { [P in keyof A]: A[P] }
type Foo = { a?: number; b: string; c?: boolean; } // 测试用例 type SomeRequired = SetRequired; type B = Pick & Required type SetRequired = Tool
1. 数组转联合类型 ```ts // 将数组类型转为联合类型后,extends判断即可 type Includes = E extends Arr2Union ? true : false type I0 = Includes // false type I1 = Includes // true type I2 =...
```ts type Tail = T extends [any, ...infer Rest] ? Rest : [] // 测试用例 type T0 = Tail // [] type T1 = Tail // [2] type T2 =...
联合类型分散后再进行联合 ```ts type Responder = { text?: () => string; json?: () => string; secure?: boolean; }; type RequireAtLeastOne< ObjectType, KeysType extends keyof ObjectType = keyof ObjectType, > = KeysType...
```ts type Unshift = T extends [...infer Arr] ? [E, ...Arr] : [] // 测试用例 type Arr0 = Unshift; // [1] type Arr1 = Unshift; // [0, 1, 2, 3]...
// 遍历并as判断 interface Example { a: string; b: string | number; c: () => void; d: {}; } // 测试用例: type StringKeysOnly = ConditionalPick; //=> {a: string} type ConditionalPick =...