-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Implicit type conversion of tuple [...T[]] to array T[] #29311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In theory they're the same, but in practice the simplification we do deletes the fact that the type should be a tuple at all, which causes the error. So, because of that, it might be best not to perform the inlining so as to preserve the tupleness of the type. |
We definitely want to keep the simplification of |
And/or having numeric-named members (eg, |
The simplification at hand makes it hard to create a tuple constraint: declare function test<T extends [...any[]]>(a: T): T
const res1 = test([1, 2])
// ^? actual: number[], expected: [number, number] There are different ways of dealing with this:
It seems that the most "complete" way of defining a tuple constraint using tuple types is... |
TypeScript Version: 3.3.0-dev.20190108
Search Terms: spread, rest, type conversion, tuple, array length
Code
Expected behaviour:
Expected
[...number[]]
and[number, ...number[]]
to have the same behaviour except that the latter requires at least one element in tuple.Actual behavior:
[...number[]]
is implicitly converted tonumber[]
with thelength: number
field, that is incompatible withlength: 2
Playground Link: 🔗
Related Issues: Haven't found anything about the same problem.
The text was updated successfully, but these errors were encountered: