microsoft / microsoft/TypeScript
Accessing protected computed property does not produce a compiler error
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
protected computed no error bug
🕗 Version & Regression Information
This is the behavior in every version I tried (v3.3.3333, v4.0.5, v5.7.3), and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
⏯ Playground Link
💻 Code
declare class Foo {
protected readonly baz = 42
}
declare class Bar {
readonly foo: Foo
}
declare const bar: Bar
// @ts-expect-error
console.log(bar.foo["baz"].toFixed(2))
🙁 Actual behavior
- (without
// @ts-expect-error): No errors - (with
// @ts-expect-error): Compiler errorUnused '@ts-expect-error' directive
🙂 Expected behavior
- (without
// @ts-expect-error): Compiler errorProperty […] is protected and only accessible within class 'Foo' and its subclasses - (with
// @ts-expect-error): No errors
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
Reproduce the behavior from the TypeScript Playground link using the provided Foo, Bar, and bracket-access example. Start by tracing compiler handling of protected-property access through an indexed access, then add coverage for the expected diagnostic and verify that the @ts-expect-error directive is consumed.
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
- 35/100