TypeScript doesn't show "Expected 1 arguments, but got 0." error, when it should.
type PolyElement = [number, number];
export interface Node {
element: PolyElement | null;
next: Node | null;
}
export class Node {
constructor(element?: PolyElement) {
this.element = element ?? null;
this.next = null;
}
add(...args: PolyElement[]) {
for (let i = 0; i < args.length; ++i) {
//some code
}
}
}
then I invoke method like so:
poly1.add([1,2,3]);
and it outputs: Argument of type '[number, number, number]' is not assignable to parameter of type 'PolyElement'. Types of property 'length' are incompatible. Type '3' is not assignable to type '2'.ts(2345)
also
poly1.add([]);
outputs: Argument of type '[]' is not assignable to parameter of type 'PolyElement'. Type '[]' is missing the following properties from type '[number, number]': 0, 1ts(2345)
etc.
The QUESTION is why:
poly1.add();
DOESN'T output something like: Expected at least 1 arguments, but got 0. ?
Argument of type '[]'.... Empty array counts as an argument, it is just of the wrong type.