You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constthree: [number,number,number]=[1,2,3];consttwo: [number,number]=[1,2];constone: [number]=[1];constfoo=(a: number,b: number,c: number)=>undefined;// EXPECTED: correctly realizes there are three argsfoo(...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".
I'm changing this to a suggestion as the current behavior is actually intended. From the description in #24897:
When a function call includes a spread expression of a tuple type as the last argument, the spread expression corresponds to a sequence of discrete arguments of the tuple element types.
A spread expression in any position but the last is always processed as a spread of an array type, i.e. we consider it to contribute an unknown number of arguments.
A key issue with this suggestion is whether we're willing to trust that a fixed-length tuple type always has exactly the declared fixed length. We do the best we can to check it, but it is obviously easy to circumvent.
I was just going through my open bug reports and looked at my playground link.
The behavior seems to have changed with TS 4.0 and variadic tuple types.
TypeScript Version: 3.3.0-dev.20190103
Search Terms: tuple, array, spread, arguments, length
Code
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:
The text was updated successfully, but these errors were encountered: