DEV Community

Discussion on: Advanced TypeScript Exercises - Answer 3

Collapse
 
macsikora profile image
Pragmatic Maciej

Yes exactly, if we have static number of elements then we should use tuple type. Using number[] means we allow any number of arguments of type number.

function f(...[a, b]: number[]) { }
function g(...[a, b]: [number, number]) { }

f(1, 2, 3) // allowed
g(1,2,3) // only two allowed so error