microsoft / microsoft/TypeScript
Object literal getters and setters doesn't work after spread syntax (ES2017 and below)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
The getters/setters will become normal/plain properties if a spread assignment is used before them.
🔎 Search Terms
Getter, setter, spread
🕗 Version & Regression Information
4.3.5
⏯ Playground Link
Playground link with relevant code
💻 Code
var Foo = {
key: 'value'
}
var Bar = {
... Foo, // this breaks the getters/setters after it.
get name() { console.log(9); return this._name },
set name(name) { this._name = `1${name}`},
_name: '',
}
🙁 Actual behavior
name setter and getter on the Bar object are “removed” and replaced with a plain name property, given that after compilation, the method used is Object.assign to piece the objects together.
🙂 Expected behavior
Getters and setters on Bar should still remain.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Playground and the object-literal spread example, then inspect the ES2017-and-below emit that uses Object.assign. Compare the generated behavior with the expected getter and setter behavior; done means accessors on Bar remain functional after compilation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100