Skip to content

Accessing protected computed property does not produce a compiler errorΒ #60974

Open
@parzhitsky

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

https://tsplay.dev/wjdn7m

πŸ’» 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 error Unused '@ts-expect-error' directive

πŸ™‚ Expected behavior

  • (without // @ts-expect-error): Compiler error Property […] is protected and only accessible within class 'Foo' and its subclasses
  • (with // @ts-expect-error): No errors

Additional information about the issue

No response

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions