-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Bad error message for assigning empty array to tuple type #6524
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
@sandersn @DanielRosenwasser would this be fixed by the proposed contextual typing changes? |
If I understand things correctly, you should get Even if you didn't, I think I've concluded on several occasions with @JsonFreeman and @CyrusNajmabadi that surfacing the |
You don't think it gives the impression of being a compiler bug? |
That's what I argued at the time because it totally looks like we screwed up somehow. The fact that we're surfacing the |
I checked, looks like the error with the change in #6118 is still the same. |
Is there such thing as a tuple of length 0? It seems like the error ought to say something like
where This is not to say that the type |
Is this still a bug given that the |
(1.9.0-dev.20160402) foo.ts: var x = [];
foo.d.ts: declare var x: any[]; foo.ts: var x: [number] = [];
There's no difference with So is an empty array |
For the tuple case, it doesn't really matter what the element type is. The array literal is required to have an element at index 0 because of the contextual type, but it does not. For the other case, if the array did not get widened to Both of these ideas are independent of strict null checking. That said, I still think it would be reasonable to have tuples of length 0, and then the message would talk about the type |
We have empty tuples now, and the new message is
|
Reported in the IRC channel against 1.7.5. Still exists in 1.8.0-dev.20160117
I guess
undefined
comes from the fact that the RHS array is empty, so its element type is left uninitialized. Maybe you want to detect that and have a different error message? "An empty array is not assignable to type [number]." or something.The text was updated successfully, but these errors were encountered: