microsoft / microsoft/TypeScript

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

オープン
#61,484 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る
Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、Issue で説明されている “Find All References” を使った TypeScript の例と inferFromUsage のケースを再現します。参照検索と使用状況の推論の際にインターフェースの実装がどのように関連付けられるかを追跡し、次に Bar.transform と Baz.transform が独立して扱われることを示す、対象を絞ったカバレッジを追加します。結果と推論された型が期待される動作と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。