microsoft / microsoft/TypeScript
"Find All References" shows all interface implementations instead of specific class method references
Chưa có ai nhận issue này.
- 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ả
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)
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ TypeScript với “Find All References” và trường hợp inferFromUsage được mô tả trong issue. Truy vết cách các triển khai interface được liên kết trong quá trình tra cứu tham chiếu và suy luận từ cách sử dụng, sau đó thêm coverage tập trung cho thấy Bar.transform và Baz.transform được xử lý độc lập; công việc được xem là hoàn tất khi kết quả và các kiểu được suy luận khớp với hành vi mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100