Microsoft/TypeScript
在 GitHub 查看JavaScript Intellisense doesn't detect types of properties defined in async constructors
Open
#61,137 建立於 2025年2月7日
Domain: JavaScriptHelp WantedPossible Improvement
倉庫指標
- Star
- (48,455 star)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 9 個 PR)
描述
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.
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
- Open a blank JavaScript, and paste in the following code:
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;
})();
}
}
- Hover over
yinClass1and observe the tooltip:(property) Class1.y: number - Hover over
yinClass2and 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