I need a function that will only take a second argument when certain conditions are met.
let func = <T extends boolean>(arg1: T, arg2: T extends true ? void : string) => {};
func(true); // ERROR Expected 2 arguments, but got 1
func(true, undefined); // OK
func(false, ''); // OK
This behavior is strange, especially because typing a function argument as void does not require it to be passed in a call. For example:
let func1 = (arg: void) => {};
func1(); // OK