Why this simple code
const arr: [string, number] = ['str', 1]; function fn(arg1?: string, arg2?: number): void { alert(arg1); } fn(...arr); produces this error:
Argument of type 'string | number' is not assignable to parameter of type 'string'. Type 'number' is not assignable to type 'string'.
When I change my call to
fn(arr[0], arr[1]) everything works fine.
Why spread does not work as expected? Why type is also converted to 'string | number'? Shouldn't it detect that the first one is a string and the latter is a number?