microsoft / microsoft/TypeScript
JavaScript Intellisense doesn't detect types of properties defined in async constructors
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
# 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
Contributor guide
Research direction
Reproduce the issue in VS Code with the provided Class1 and Class2 examples and compare the hover types with extensions disabled. Trace the TypeScript language-service handling of JavaScript IntelliSense for async constructors, then add regression coverage; done means Class2.y is inferred as number like Class1.y.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100