Skip to content
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

Class instance + spread assignment allows wrong type guarantee #23363

Closed
payload opened this issue Apr 12, 2018 · 2 comments
Closed

Class instance + spread assignment allows wrong type guarantee #23363

payload opened this issue Apr 12, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@payload
Copy link

payload commented Apr 12, 2018

Consider this example:

let x = new RegExp('');
console.log(x);
x = { ...x };
console.log(x);

The spread operator in the object literal produces a new type different vom the RegExp type of x.
The bad thing happens when the type checker allows the assignment of this object to x of type RegExp.
For example x has non of the methods of RegExp afterwards.
I expect that the compiler rejects assigning a value of wrong type to x.

Compile it with tsc --lib es6,dom foo.ts && node foo.js and get the output:

/(?:)/
{}

playground

@payload payload changed the title Class instance spread assignment Class instance + spread assignment allows wrong type guarantee Apr 12, 2018
@RyanCavanaugh
Copy link
Member

See comments in #13148 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 12, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants