How can I call a generic function with just one generic parameter when the second one is needed on the fly?
问题 I have a generic function with two parameters. The second one is based on the value of first parameter. The code works with just one type variable but when I add another one, cannot call the function. This works perfectly: type Event<T> = T extends 'string' ? string : number; type input = 'string' | 'number'; function test<U extends input>(module: U, event: Event<U>) { //... } //No errors test('number', 2); // Generates error as expected test('string', 2); But when another generic variable is