-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Spreading array into object should not be assignable to array #28801
Comments
The main problem is that builtin types are declared as interface in lib.xxx.d.ts. If Unfortunately class declarations of the same name are not able to merge, which makes it impossible to add |
I think Or function foo (evt : MouseEvent) {
const copy = {...evt};
console.log(copy.x + 1); //undefined + 1 = NaN
} |
isn't |
The problem is that |
Tracking at #9726 |
I just ran into this same thing, so created a test code case:
I should get a compile warning on the thingThatShouldNotHappen; I don't. TS 3.5.3 |
TypeScript Version: 3.3.0-dev.20181129
Search Terms: spread array object
Code
Expected behavior:
{ ...x }
should not be assignable tonumber[]
Actual behavior:
{ ...x }
is assignable tonumber[]
and results in run-time errors.Playground Link: here
I actually ran into this problem because I was refactoring some code and decided to use arrays instead of objects. However, I missed a few spots. Luckily, I had unit tests to scream at me.
The text was updated successfully, but these errors were encountered: