// Quirky function that serves no real purpose
function myFunction(x: number, y?: number[], z?: number): string | boolean {
if (y === undefined)
return false;
y.push(x);
if (z) y.push(z);
return y.toString();
}
const boolTypeResult = myFunction(5); // type: boolean | string
const boolTypeValue = myFunction(5, undefined, 8); // type: boolean | string
const stringValue = myFunction(9, [], 0); // type: boolean | string
Can we modify myFunction() to determine the return type based on the second optional parameter value, while keeping the order of the parameters?