I want to specify how the rest of the array should look without knowing how many values the array will have. How can I achieve something like this? (playground version here):
type numStrArr = [number, ...string];
let arr: numStrArr = [1, 'hi', 'other string'];
The above code throws the error Type expected.
at the spread operator, however.
I'm aware that there was a proposal for this, but how can I achieve similar behavior now?
[number, string]
or{0: number, [i: number]: string | number}
, but both of them would type additional params asnumber | string
, notstring
. Closest you could get is probably something like[number, string, string, string, string, string, string]
. – Gorgeous