microsoft / microsoft/TypeScript

importModuleSpecifier "shortest" does not choose shortest result among multiple matching paths aliases

Đang mở
#63,320 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
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ả

### 🔎 Search Terms

importModuleSpecifier shortest paths multiple aliases, auto import paths overlapping alias, tryGetModuleNameFromPaths shortest

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about auto-import and paths

### ⏯ Playground Link

N/A — this is a language service auto-import behavior that requires a multi-file project with jsconfig/tsconfig `paths`

### 💻 Code

```json
// jsconfig.json
{
"compilerOptions": {
"paths": {
"@@/*": ["./*"],
"@/*": ["./src/*"]
}
}
}
```
```js
// src/services/foo.js
export function foo() {}

// src/index.js — trigger auto-import for `foo`
```

### 🙁 Actual behavior

Auto-import suggests `@@/src/services/foo`. The `importModuleSpecifier: "shortest"` preference does not influence the choice between two matching `paths` aliases. `tryGetModuleNameFromPaths` returns on the first matching key in iteration order without comparing alternatives.

### 🙂 Expected behavior

With `importModuleSpecifier` set to `"shortest"`, auto-import should compare all matching aliases and suggest `@/services/foo` since it is shorter than `@@/src/services/foo`.

### Additional information about the issue

Workaround is to reorder `paths` entries so the more specific alias appears first, relying on object key insertion order. This is fragile and undocumented.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Start at the mentioned tryGetModuleNameFromPaths entry point and reproduce the multi-file auto-import case using the jsconfig/tsconfig paths configuration. Trace how matching aliases are selected, then verify that the shortest preference produces the shorter alias rather than depending on object key order.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
52/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.