heweijian4933

Results 4 comments of heweijian4933

// 楼上我没细看, 但是大部分人的答案其实都有瑕疵 瑕疵的地方在于 > Typescript 当中, Function extends object为 true(Function 是 object/Record的子类型), 也就是如果将测试用例更改为提取`object`类型而不是'string'等类型的话, 这个时候 Function 类型也会被并入 ``` // 瑕疵版本案例 type ConditionalPick = { [K in keyof T as (T[K]...

type Foo = { readonly a: number; readonly b: string; readonly c: boolean; }; type RemoveReadonly={ -readonly [K in keyof T]: T[K] } type Mutable = Omit & RemoveReadonly const...

可能是比较简洁好懂的写法了 > 每次看到这种需要循环处理的题目第一反应是想到递归 ``` type ToPath = S extends `${infer First}.${infer Rest}` ? First extends `${infer InnerFirst}[${infer Num}]` ? [InnerFirst,Num,...ToPath] : [First,...ToPath] : [S] type Res1 = ToPath //=> ['foo',...

> 索引一般是 `string`衍生的属性名,而可索引签名不是,可以根据这个来过滤掉可索引签名: ``` interface Foo { [key: string]: any; [key: number]: any; bar(): void; } type RemoveIndexSignature = { [K in keyof T as K extends `${infer Str}`? Str...