microsoft / microsoft/TypeScript
No error when accessing setter-only properties
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
"setter only", "setter-only"
🕗 Version & Regression Information
- This behavior is present in the current version of TypeScript, 5.4.4
⏯ Playground Link
💻 Code
class Foo {
set bar(baz: string) { }
}
const foo = new Foo();
const value: string = foo.bar; // This assignment should not be allowed, foo.bar will always be undefined!
🙁 Actual behavior
There is no error reported during type-checking.
🙂 Expected behavior
The type-checking should report an error for the assignment in the last line as foo.bar will always be undefined.
Additional information about the issue
#21759 is related, but that issue proposes a whole new language feature, this issue is solely about the lack of a type error.
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 and reproduce the setter-only property assignment to confirm the current type-checking behavior. Trace the type-checker path involved in reading foo.bar, then add coverage showing that assigning the read result to string reports an error without implementing the separate feature discussed in #21759.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100