microsoft / microsoft/TypeScript
Auto import option to make imports relative only within current directory
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
🔍 Search Terms
import relative
✅ 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.
⭐ Suggestion
An option added to the importModuleSpecifier preference to make imports absolute if and only if their relative path would begin with ../.
📃 Motivating Example
At my workplace, our least favourite relative imports are the ones that venture out of the current directory (i.e. they begin with any number of ../). But there are times where we want relative imports within the current directory (i.e. beginning with ./). I don't see any existing options that support this exact style of import, including project-relative.
In general, the motivation for not using relative imports beginning with ../ is that it makes moving code files around more difficult.
💻 Use Cases
shortest and relative are obviously not correct since they have no qualms about this issue.
non-relative is my current workaround, which only adds absolute imports.
project-relative I tried, but based on what I discovered and my understanding of the description in the tooltip, my guess is that it only adds absolute imports for files that are located outside of the workspace folder.
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 localizando el manejo de la preferencia importModuleSpecifier en el servicio de lenguaje y siguiendo cómo elige entre especificadores de módulo relativos y absolutos. Revisa las pruebas existentes para las preferencias de autoimportación y, después, añade cobertura que muestre que las rutas que comienzan por ../ usan imports absolutos, mientras que los imports dentro del directorio actual siguen siendo relativos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100