我有一个联合类型的函数:
function Function1(arg0: string, arg1: any[], name: "hello" | "bye") {
return name;
}
function Function2(arg0: string, arg1: any[], name: "foo" | "bar") {
return name;
}
type Functions = typeof Function1 | typeof Function2;
现在我想创建一个类型,它接受一个元组,其中第一个位置是实际函数,第二个位置是相应的"name"参数.
const baz = [Function1, "foo"];
我试过这个:
type FooBar<T = Functions> = [T, Parameters<T>[2]];
首先,它给出一个错误Parameters<T>[2]
"类型‘T’不满足约束‘(...args:any)=>;any’"
"
它几乎可以工作,但我从两个函数中获得了所有参数.