microsoft / microsoft/TypeScript
Add quick fix to convert type-only import into normal import
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
convert type import
Suggestion
I'd like to have a quick fix to convert a type-only import into a normal import if the imported type is used in a value position.
Use Cases
Now that #36400 is supported, TypeScript auto-creates type-only imports for us. However, if we later decide to use the imported type in a value position, the described workflow in #36400 is still awkward. By adding a quick fix, TypeScript could make this more smooth for the developer.
Examples
import type { Foo } from "./foo";
// ... 1000 lines below
const something = Foo.staticMethod();
// ~~~ Error: Foo cannot be used as a value
When placing the cursor on Foo here, TypeScript should offer converting the type-only import into a normal import.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 riproducendo l'esempio con import type { Foo } from "./foo" e un uso in posizione di valore come Foo.staticMethod(). Esamina il comportamento esistente della correzione rapida per la diagnostica e determina come dovrebbe cambiare l'import. Il lavoro è completato quando il cursore sull'uso in posizione di valore offre una correzione rapida che converte l'import di solo tipo in un import normale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100