Description
TypeScript Version: 3.1.0-dev.20180809
Search Terms: tuple spread function call
Code
function foo (a: 1, b: 2, c: 3) { }
const bar: [1, 2] = [1, 2];
foo(...bar, 3);
Expected behavior:
No error.
Actual behavior:
On the third line: Expected 3 arguments, but got 1 or more.
Notes:
If this is intended to work this way, or is simply not implemented yet, this issue can be edited into a feature request.
First use case I can think of is my Vector2/3
classes, which support xy: [number, number]
and xyz: [number, number, number]
. I have some methods which require x, y, and z values, and do not want a vector (legacy code). It would be nice to be able to spread into them.
Another use pertaining to my vector example is constructing a V3 from a V2, new Vector3(...v2.xy, z)
Also, this already works if the tuple exactly matches the method call, example:
const baz: [1, 2, 3] = [1, 2, 3];
foo(...baz);