microsoft / microsoft/TypeScript

Incorrect TS1111 when using private generator function in JS

オープン
#64,228 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
Needs More Info
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔎 Search Terms

An error TS1111 is raised when (properly) using a private generator function. I'm using VSCode, and it will report `Private field '#iterate' must be declared in an enclosing class.` when calling `child.#iterate()`.

### 🕗 Version & Regression Information

- I'm hitting this in VSCode 1.135.0

### 💻 Code

```js
class Foo {
*iterate() {
yield* this.#iterate()
}

*#iterate() {
const child = this.child
if (child instanceof this.constructor) {
yield* child.#iterate()
}
}
}

let f = new Foo()
for (const i of f.iterate()) {

}
```

### 🙁 Actual behavior

An error TS1111 is raised.

### 🙂 Expected behavior

There should be no error.

### Additional information about the issue

1. The error disappears if I call `this.#iterate()`, but of course that's not the point.
2. I can also clear the error by adding `assert(#iterate in child)` before the call

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

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

調査の方向性

ソースファイルもテストも指定されていません。まず、VSCode 1.135.0 で提供された private-generator の例から TS1111 診断を再現し、次に `child.#iterate()` の呼び出しに対するコンパイラの private フィールドチェックを追跡してください。例でエラーが発生せず、妥当なアクセスをカバーする回帰テストが追加されれば完了です。

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

評価

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

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

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