microsoft / microsoft/TypeScript

"Find All References" shows all interface implementations instead of specific class method references

Ouverte
#61,484 1 commentaire 2 réactions 0 personnes assignées Voir sur GitHub
Awaiting More Feedback Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

When using VS Code's **"Find All References"** on a class method that implements an interface method, the results include all instances where the method is defined (e.g., in the interface and other implementing classes). However, I expected it to show only references specific to the selected class implementation.

#### **Steps to Reproduce:**
1. Create a TypeScript file with the following code:
```ts
export declare interface Transform {
transform(value: any, ...args: any[]): any;
}

export class Bar implements Transform {
transform() {}
}

export class Baz implements Transform {
transform() {}
}
```
2. Right-click on the `transform` method inside the `Bar` class.
3. Select **"Find All References"** from the context menu.
4. The results include all occurrences of `transform`, including the interface definition and the implementation in `Baz`.

#### **Expected Behavior:**
VS Code should return only the references specific to `Bar`'s implementation of `transform`.

#### **Actual Behavior:**
The search includes all references to `transform` across the interface and other implementations, making it difficult to isolate usages of `Bar.transform`.

---

### Impact on "inferFromUsage"

The behavior also affects TypeScript's **"inferFromUsage"** feature:

```ts
export declare interface Transform {
transform(value: any, ...args: any[]): any;
}

export class Bar implements Transform {
transform(value) { } // <-- Inferred: value is a number
}

export class Baz implements Transform {
transform(value) { } // <-- Also inferred as a number, even though Baz is unused
}

new Bar().transform(1);
```

Since `Bar.transform(1)` is explicitly called, TypeScript infers `value` as a `number`. However, `Baz.transform` also gets the same inferred type **even though it's never used**. This suggests that TypeScript applies inference across all implementations of the interface, rather than treating them independently.

[[🔗 TypeScript AST Viewer](https://ts-ast-viewer.com/#code/KYDwDg9gTgLgBAE2AYwDYEMrDgSwHYzBQBm6y2AKlOngM7HQC2cA3gFBydwzV0NSMAFADd0qAK7AAXHBoBPADRwAdKswBzWjPkBtALoBKbXjkBuNgF82bUJFhw06WrTgAhTLkZhUwRsAIuVDT0TKwcXDzB-EKiEsAGrHBWVjbg0PCOzm7oAF6e3r7+MIG8IQJhXNyl0SJikgksSZbWeMAA7tlQggbKkXxMggCMBuZAA)](https://ts-ast-viewer.com/#code/KYDwDg9gTgLgBAE2AYwDYEMrDgSwHYzBQBm6y2AKlOngM7HQC2cA3gFBydwzV0NSMAFADd0qAK7AAXHBoBPADRwAdKswBzWjPkBtALoBKbXjkBuNgF82bUJFhw06WrTgAhTLkZhUwRsAIuVDT0TKwcXDzB-EKiEsAGrHBWVjbg0PCOzm7oAF6e3r7+MIG8IQJhXNyl0SJikgksSZbWeMAA7tlQggbKkXxMggCMBuZAA)

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par reproduire l’exemple TypeScript avec « Find All References » et le cas inferFromUsage décrit dans l’issue. Suivez la manière dont les implémentations d’interfaces sont associées lors de la recherche de références et de l’inférence à partir de l’utilisation, puis ajoutez une couverture ciblée montrant que Bar.transform et Baz.transform sont traitées indépendamment ; le travail est terminé lorsque les résultats et les types inférés correspondent au comportement attendu.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.