microsoft / microsoft/TypeScript
Getting a setter-only property is typed as the setter's parameter's type instead of undefined
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
setter only
🕗 Version & Regression Information
- This is the behavior in every version I tried, from 5.7.3 down to 3.3.3333
⏯ Playground Link
💻 Code
const language = {
set current(name: string) {
this.log.push(name);
},
log: [] as string[],
};
language.current = "FR";
const c = language.current;
🙁 Actual behavior
Variable c is said to be of type string.
🙂 Expected behavior
As clearly stated here, it should be undefined.
Note that
currentis not defined, and any attempts to access it will result inundefined.
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 with the linked TypeScript Playground example and confirm that reading the setter-only property is typed as string rather than undefined. Trace the compiler logic that determines the type of an accessor read, then add coverage for this object-literal setter case and verify that the inferred type is undefined without regressing valid getter/setter behavior.
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
- 45/100