microsoft / microsoft/TypeScript
[TypeScript] Mapped Types with Template Literal Keys Do Not Preserve Type Declaration 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ả
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.96.4 (Universal)
- OS Version: Darwin arm64 23.6.0 (macOS Sonoma 14.7.2)
- TypeScript Version: 5.7.3
When using Mapped Types with template literal transformations on interface fields, VSCode does not retain the original type reference. This makes it impossible to use “Go to Definition” to navigate from the transformed key back to its original declaration. WebStorm correctly maintains this reference, but VSCode does not.
Steps to Reproduce:
``` ts
interface Source {
alpha: number;
beta: string;
}
// Transforming interface field names with a suffix
type Transformed = {
[K in keyof T as `${K & string}Suffix`]: () => T[K];
};
type Result = Transformed;
/*
Expected:
{
alphaSuffix: () => number;
betaSuffix: () => string;
}
*/
const obj: Result = {
alphaSuffix: () => 42,
betaSuffix: () => "hello",
};
// ❌ In VSCode, "Go to Definition" on `alphaSuffix` does not navigate to `alpha` in `Source`
obj.alphaSuffix();
```
### Expected Behavior
- “Go to Definition” on alphaSuffix should navigate to alpha in Source.
- VSCode should retain the reference between transformed keys and their original interface field names.
- This works as expected in WebStorm, where alphaSuffix correctly links back to alpha.
### Actual Behavior
- VSCode treats transformed keys as completely new identifiers, losing the connection to their original interface fields.
- “Go to Definition” does not work for mapped types with template literal keys.
- WebStorm successfully tracks the transformation and allows navigation to alpha.
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
Tái hiện ví dụ về mapped types bằng TypeScript 5.7.3 và kiểm thử Go to Definition từ `alphaSuffix` đến `Source.alpha`. Bắt đầu bằng cách lần theo quá trình tra cứu định nghĩa của dịch vụ ngôn ngữ TypeScript đối với mapped types và các khóa template literal; được coi là hoàn tất khi khóa đã biến đổi điều hướng đến trường trong interface gốc của nó và hành vi này có kiểm thử hồi quy.
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
- developer-experience
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- 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