microsoft / microsoft/TypeScript

JavaScript Intellisense doesn't detect types of properties defined in async constructors

未关闭
#61,137 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
Domain: JavaScript Help Wanted Possible Improvement
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

# JavaScript Intellisense doesn't detect types of properties defined in async constructors
## Summary
A popular asynchronous constructor pattern in JavaScript is using an async IIFE in the constructor which returns `this` at the end. E.g.
```javascript
constructor() {
return (async () => {
this.#x = 42;
this.y = 42;

return this;
})();
}
```

However, VSCode Intellisense does not infer the types for properties defined in such a constructor.

## Steps to reproduce
1. Open a blank JavaScript, and paste in the following code:
```javascript
class Class1 {
#x;
y;
constructor() {
this.#x = 42;
this.y = 42;
}
}
class Class2 {
#x;
y;
constructor() {
return (async () => {
this.#x = 42;
this.y = 42;

return this;
})();
}
}
```
2. Hover over `y` in `Class1` and observe the tooltip: `(property) Class1.y: number`
3. Hover over `y` in `Class2` and observe the tooltip: `(property) Class2.y: any`

Does this issue occur when all extensions are disabled?: **Yes**

- VS Code Version: 1.97.0
- OS Version: Windows 11

贡献指南

打开贡献指南

调研方向

使用提供的 Class1 和 Class2 示例在 VS Code 中重现该问题,并在禁用扩展后比较悬停类型。跟踪 TypeScript language-service 对异步构造函数的 JavaScript IntelliSense 处理,然后添加回归测试覆盖;完成标准是 Class2.y 与 Class1.y 一样被推断为 number。

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

评估

技术栈
javascript, typescript, vscode
领域
developer-experience, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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