Closed
Description
TypeScript Version: 3.3.0-dev.20190103
Search Terms: tuple, array, spread, arguments, length
Code
const three: [number, number, number] = [1, 2, 3];
const two: [number, number] = [1, 2];
const one: [number] = [1];
const foo = (a: number, b: number, c: number) => undefined;
// EXPECTED: correctly realizes there are three args
foo(...three);
// EXPECTED: correctly realizes there are two args
// error: Expected 3 arguments, but got 2.
foo(...two);
// EXPECTED: correctly realizes there is one arg
// error: Expected 3 arguments, but got 1.
foo(...one);
// UNEXPECTED: does not realize there are three args
// error: Expected 3 arguments, but got 1 or more.
foo(...two, 2);
// UNEXPECTED: does not realize there are three args
// error: Expected 3 arguments, but got 1 or more.
foo(...one, 2, 3);
Expected behavior:
Correctly calculate the count of the arguments passed into foo
. Add the additional arguments to the length of the tuple. Basically the last two examples should not throw an error.
Actual behavior:
When adding additional arguments after the spreaded tuple, TS fails to calculate the total amount of arguments end expects the amount of the additional arguments "+ more".
Playground Link: Link
Related Issues: