microsoft / microsoft/TypeScript
JS `Object.defineProperty` declaration can't define divergent accessors
Open
Nobody has claimed this yet.
Domain: JavaScript
Experience Enhancement
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
divergent accessors setter getter expando js jsdoc
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
const x = {};
Object.defineProperty(x, "test", {
/** @returns {string} */
get() {
return "";
},
/** @param {number} a */
set(a) {},
});
function isolateFromExpandoAssignmentsBinding() {
x.test = 42; // error but should be OK
}
🙁 Actual behavior
The write type of this expando member is string
🙂 Expected behavior
The write type of this expando member should be number since divergent accessors are allowed nowadays
Additional information about the issue
No response
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 by running the playground link and the minimal Object.defineProperty example to reproduce the divergent getter and setter types. Trace how the TypeScript type checker determines the write type for this expando member, then verify that x.test accepts number while preserving the getter's string type.
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
- 38/100