Appearance
前置不确定参数
题目
ts
addImpl("string", "boolean", "number", (a, b, c) => {});
addImpl("string", "boolean", "number", (a, b, c) => {});
1
解法
ts
type JSTypeMap = {
string: string;
boolean: boolean;
number: number;
function: Function;
object: object;
symbol: symbol;
undefined: undefined;
bigint: bigint;
};
type JSTypeName = keyof JSTypeMap;
type ArgsType<T extends JSTypeName[]> = {
[I in keyof T]: JSTypeMap[T[I]];
};
declare function addImpl<T extends JSTypeName[]>(
...args: [...T, (...args: ArgsType<T>) => void]
): void;
type JSTypeMap = {
string: string;
boolean: boolean;
number: number;
function: Function;
object: object;
symbol: symbol;
undefined: undefined;
bigint: bigint;
};
type JSTypeName = keyof JSTypeMap;
type ArgsType<T extends JSTypeName[]> = {
[I in keyof T]: JSTypeMap[T[I]];
};
declare function addImpl<T extends JSTypeName[]>(
...args: [...T, (...args: ArgsType<T>) => void]
): void;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17