This question may have been posed previously, but unfortunately I lack suitable search terms.
When parameters are changed to a union, it seems to enforce strict parameter counting. This can lead to:
a) the unnecessary requirement of dummy parameters:
// Works.
const f: (...args: [x: string, y: boolean] ) => void = ( ) => {};
const g: (...args: [x: string, y: boolean] ) => void = (n ) => {};
const h: (...args: [x: string, y: boolean] ) => void = (n, m) => {};
// Still works.
const i: (...args: [x: string, y: boolean] | [x: string, y: symbol]) => void = ( ) => {};
const j: (...args: [x: string, y: boolean] | [x: string, y: symbol]) => void = (n, m) => {};
// Source has 2 element(s) but target allows only 1.(2322)
const k: (...args: [x: string, y: boolean] | [x: string, y: symbol]) => void = (n ) => {};
b) potentially invalid assignments in absence of a union:
// Works.
const f: (...args: any[]) => void = (...args: [number, string] ) => {};
// Target requires 2 element(s) but source may have fewer.(2322)
const g: (...args: any[]) => void = (...args: [number, string] | [string, number]) => {};
What causes this behavior and is there a way to enforce one over the other, regardless of parameter appearance?
PS: with strictFunctionTypes
, which is now the default setting