microsoft / microsoft/TypeScript

Incorrect TS1111 when using private generator function in JS

未关闭
#64,228 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Needs More Info
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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()` 调用的私有字段检查。示例不再产生错误,并且回归测试覆盖有效访问后,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。