type A = {
aa: string;
bb: number;
};
type G = {
<T extends keyof A>(a: T): A[T];
<T1 extends keyof A, T2 extends keyof A>(a: T1, b: T2): [A[T1], A[T2]];
// ...
};
const g = {} as G;
const x = g('aa'); //string
const y = g('bb', 'aa'); //[number, string]
const z = g('bb', 'aa', 'cc'); //Expected 1-2 arguments, but got 3
How can I handle an arbitrary number of parameters and retrieve the corresponding types?