microsoft / microsoft/TypeScript
Private class field helpers throw a confusing error when in unbound method with undefined `this`
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
this undefined bind private identifier class __classPrivateFieldSet __classPrivateFieldGet bound unbound
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
class Foo {
#value = 1234;
getValue() { return this.#value; }
}
const foo = new Foo();
console.log(`foo.getValue() = ${foo.getValue()}`);
// Oops, I didn't bind!
const getValue = foo.getValue;
// Throws: Cannot read private member from an object whose class did not declare it
console.log(`getValue() = ${getValue()}`)
🙁 Actual behavior
Throws Cannot read private member from an object whose class did not declare it.
But the actual problem is that this is undefined and I had no idea!
🙂 Expected behavior
A special error for this when undefined; IIRC there's no possible way this would normally pass, so a special error would be a lot more clear.
Additional information about the issue
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた TypeScript Playground で束縛されていない private-field へのアクセスを再現し、issue に示されている束縛された呼び出しと比較します。コンパイラーが生成した private-field ヘルパーがどのように失敗を報告するかを追跡し、次に undefined-this のケースで説明されている、より明確なエラーが発生するようにして、両方の例を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100