Microsoft/TypeScript

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

Open

#61 137 ouverte le 7 févr. 2025

Voir sur GitHub
 (0 commentaires) (1 réaction) (0 assignés)TypeScript (6 726 forks)batch import
Domain: JavaScriptHelp WantedPossible Improvement

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

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.

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:
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;
		})();
	}
}
  1. Hover over y in Class1 and observe the tooltip: (property) Class1.y: number
  2. 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

Guide contributeur