microsoft / microsoft/TypeScript
Incorrect TS1111 when using private generator function in JS
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 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
Contributor guide
Research direction
No source file or test is named. Start by reproducing the TS1111 diagnostic from the provided private-generator example in VSCode 1.135.0, then trace the compiler's private-field checking for the `child.#iterate()` call. Done means the example produces no error and a regression test covers the valid access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100