microsoft / microsoft/TypeScript

Accessing protected computed property does not produce a compiler error

オープン
#60,974 コメント 7 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Foo、Bar、およびブラケットアクセスの例を使って、TypeScript Playground のリンクにある動作を再現します。まず、インデックスアクセスを介した protected プロパティへのアクセスをコンパイラがどのように処理するかを追跡し、次に期待される診断のカバレッジを追加して、@ts-expect-error ディレクティブが消費されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。