Is it possible to make a function have either mandatory or optional parameters based on conditional types in TypeScript?
This is what I've got so far:
const foo = <T extends string | number>(
first: T,
second: T extends string ? boolean : undefined
) => undefined;
foo('foo', true); // ok, as intended
foo(2, true); // not ok, as intended
foo(2, undefined); // ok, as intended
foo(2); // compiler error! I want this to be ok