microsoft / microsoft/TypeScript
Improve behavior of typescript.preferences.importModuleSpecifier: non-relative
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
⭐ Suggestion
Currently, with this setting"typescript.preferences.importModuleSpecifier": "non-relative" VScode goes to the tsconfig file and checks both baseUrl and paths and look for a match.
The situation that I experience is having a few paths in my path property and they sometimes overlap.
Example:
"baseUrl": ".",
"paths": {
"*": ["src/main/*"],
"utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
},
With this configuration I can import a function from the utilsFunctions folder in one of these 2 options:
import { foo } from "src/main/utils/utilsFunctions/functions.tsimport { foo } from "utilsFunctions/functions.ts
Both of these import statements will work.
But If I add foo in my code without writing the import statement myself, vscode will auto-suggest me to use option no. 1, but In my case, I actually wanted option no.2 (in the above options).
Requested behavior:
When using foo (without it importing it first), VScode should suggest me both options.
My solution, in this case, was to reverse the order of paths like this:
"paths": {
"utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
"*": ["src/main/*"],
},
🔍 Search Terms
importModuleSpecifier
✅ Viability Checklist
My suggestion meets these guidelines:
- [ ✅ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [ ✅ ] This wouldn't change the runtime behavior of existing JavaScript code
- [ ✅ ] This could be implemented without emitting different JS based on the types of the expressions
- [ ✅ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [ ✅ ] This feature would agree with the rest of TypeScript's Design Goals.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo el caso de tsconfig baseUrl y paths superpuestos con typescript.preferences.importModuleSpecifier establecido en non-relative. Traza cómo se selecciona la sugerencia de importación y determina cómo deberían presentarse ambos especificadores de módulo válidos; se considera terminado cuando se sugieren las alternativas solicitadas sin cambiar el comportamiento de ejecución existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript, vscode
- Área
- developer-experience, tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100