microsoft / microsoft/TypeScript
Auto import option to make imports relative only within current directory
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando la gestione della preferenza importModuleSpecifier nel servizio del linguaggio e tracciando il modo in cui sceglie tra specificatori di modulo relativi e assoluti. Controlla i test esistenti per le preferenze di auto-importazione, quindi aggiungi una copertura che dimostri che i percorsi che iniziano con ../ usano import assoluti, mentre gli import all’interno della directory corrente rimangono relativi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100