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

Using spread operator breaks typechecking #15908

Closed
sh-rp opened this issue May 17, 2017 · 3 comments
Closed

Using spread operator breaks typechecking #15908

sh-rp opened this issue May 17, 2017 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@sh-rp
Copy link

sh-rp commented May 17, 2017

My apologies if this has been reported before, I have done a search of the issues, and with the keyword spread this has not come up. I also believe that this functionality worked in TS 2.1 but is now broken.

TypeScript Version: 2.3.2

Code

interface ICar {
  wheels: number
  brand: string
}

let car:ICar = {
  wheels: 4,
  brand: 'volvo'
}

car = {
  ...car,
  legs: 5 // this should not work
}

Expected behavior:
Compile error when trying to add the legs attribute to a variable of type ICar.

Actual behavior:
Will compile and add the faulty attribute

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2017

We did discuss this in #14853 and the decision was to flag these as errors.

@mhegazy mhegazy added the Bug A bug in TypeScript label May 17, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone May 17, 2017
@sh-rp
Copy link
Author

sh-rp commented May 17, 2017

Hey @mhegazy , thanks for getting back to me so promptly. Great to hear that it is in the roadmap.

@sandersn
Copy link
Member

My old PR fixes this issue as well, so I re-opened it and will merge it after I get a review.

@sandersn sandersn added the Fixed A PR has been merged for this issue label May 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants