-
Notifications
You must be signed in to change notification settings - Fork 13.3k
JSDoc @type does not attach to for loop variable declarations #43756
Copy link
Copy link
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Bug Report
From what I could tell, this is a common pattern with JSDoc used to properly document the type of a loop variable. It does not seem to work in VSCode.
🔎 Search Terms
jsdoc for loop type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSDoc.
⏯ Playground Link
💻 Code
for (/** @type {HTMLElement} */ const e of document.body.querySelectorAll('.test')) {
e.style.display = 'none';
}🙁 Actual behavior
e is typed as Element
🙂 Expected behavior
e should be typed as HTMLElement, as I have overridden it via @type.
As an example, if I were to change the code to this:
/** @type {HTMLElement} */ const e = document.body.querySelectorAll('.test');VSCode correctly picks up that I'm wishing to override e as an HTMLElement (and complains about missing interface implementations, but, that's not the issue here - in fact that's expected!)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript