microsoft / microsoft/TypeScript

JSDoc @type does not attach to for loop variable declarations

Đang mở
#43,756 10 bình luận 8 reaction 1 người được giao Xem trên GitHub

@sandersn đang làm issue này rồi.

Từ ngày 21/4/2021.

Awaiting More Feedback Needs Investigation Rescheduled Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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

https://www.typescriptlang.org/play?#code/GYewTgBAFA9AVHCABALgTwA4FMIG8ASAKgLIAyAogDZYC2WAdigL4RwwQDGI9AzihDhDAIAExAcArnUYA6AEYgRaGQEcJWMGgDKWahxTgAgpUpQA5DJRY+ZgJS28AKAguBMvmmoyRASx4ZKAEM0CABeCDN6biwzAG5HJiA

💻 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!)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.