microsoft / microsoft/TypeScript

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

Abierto
#63,320 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔎 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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, typescript
Área
developer-experience, tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.