microsoft / microsoft/TypeScript

Comment is not infered correctly when using generic type

Open
#45,673 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: LS: Quick Info Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

generic comment

🕗 Version & Regression Information

4.4.2

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.4.2#code/JYOwLgpgTgZghgYwgAgKoGdrIN4ChkHID0AVCfocicgLICeyAwgPYC2rE4yAEtBAHSCKhEkWHIQcDgC5k6MFFABzXAF9cuIkWQBRAB4AHCAkgATTdoDqAC07IEAVyjpmUZMHTJmIZAHJJHL4ANPZsHFzMMH4BEL7IcAZGcFAQ5jAOICbA3sjpmQCMABQOmFCyGNAAlDjqeQhFeJQxsr4AGu2+apUaWmggEIbGZhbINnaOzq7unjn+UrEhIMyh7Jxg8YkQyam4dWDZPnUATAA8ACrIA5Agpp4VUAB8xaWyZ9XYtRkIR4WNhM1+dqtTqqSpAA

💻 Code
interface User {
    /**
     * My Comment Here...
     */
    name: string
}

// Expected
// When cursor is on 'name', comment of 'name' appeared
function func1(user: User) {}
func1({
    name: 'XXX'
})

// Unexpected
// When cursor is on 'name', no comment appeared
function func2<T extends User>(user: T) {}
func2({
    name: 'XXX'
})
🙁 Actual behavior

No comment for func2

image

🙂 Expected behavior

Show comment for func2

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript 4.4.2 Playground repro and compare comment inference for func1 and generic func2. Trace the comment lookup for the name property in both examples, then verify that the generic call shows “My Comment Here...” as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.