Newbie to TypeScript, and I’m confused about the folowing snippet:
type Fn = (...args: number[]) => void
const fn1: Fn = (x) => console.log(x);
const fn2: Fn = (x1, x2) => console.log(x1, x2);
fn1(2);
fn2(2, 4);
In my understanding, ...args
is a rest parameter where indefinite number of arguments is allowed and you can access args
as array, but its implementations fn1
and fn2
doesn’t implement with rest parameter or access it as array. fn1
only accept 1 argument, and fn2
accept 2 arguments only.
Is this a specific feature of rest parameter in type
keyword? If so, where can I find the specfication?
Please feel free to tell me if there’s anything unclear to you.
I expected the implementaion of Fn
should be something like
const fn: Fn = (...x: number[]) => console.log(x);