microsoft / microsoft/TypeScript
Incorrect TS1111 when using private generator function in JS
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Aucun fichier source ni aucun test n’est indiqué. Commencez par reproduire le diagnostic TS1111 à partir de l’exemple private-generator fourni dans VSCode 1.135.0, puis suivez la vérification des champs privés du compilateur pour l’appel `child.#iterate()`. Le travail est terminé lorsque l’exemple ne produit aucune erreur et qu’un test de régression couvre l’accès valide.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 55/100