Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SuperLlama88888 opened this issue Feb 7, 2025 · 0 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@SuperLlama88888
Copy link

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
@mjbvz mjbvz transferred this issue from microsoft/vscode Feb 7, 2025
@mjbvz mjbvz removed their assignment Feb 7, 2025
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Feb 7, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

3 participants