我正在try 创建一个具有两个参数的函数,这两个参数应该是相同类型的.该类型可以是类型列表中的任何类型,这些类型本身就是字符串文字的列表.
type A = "A1" | "A2" | "A3";
type B = "B1" | "B2" | "B3";
type Union = A | B;
type params<T> = T extends Union ? {input: T, output: T} : never;
function test(params: params<Union>) {
...
}
预期:
type params<Union> = {input: A, output: A} | {input: B, output: B}
会发生什么:
type params<Union> = {input: "A1", output: "A1"} | {input: "A2", output: "A2"} | {input: "A3", output: "A3"} | {input: "B1", output: "B1"} | {input: "B2", output: "B2"} | {input: "B3", output: "B3"}