microsoft / microsoft/TypeScript

Autocompletion does NOT remove `type` from `import type` when needed

Aperta
#62,882 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

We use TypeScript configuration `"verbatimModuleSyntax": true` in `tsconfig.json` and so import statements can be specified ether `import module` or `import type module`.

Previously in the case when module was imported as a type like `import type Test from 'test'` and it needs to be imported without type like `import Test from 'test'` autocompletion will remove the `type` part. With the new version this behaviour is broken and `type` part is not being removed by autocompletion.

Before
```ts
// "type" will be removed here
import type Test from 'test'; // -> import Test from 'test';

// use autocompletion -> "type: being removed from above
const test = new Test();
```

Now
```ts
// "type" stays at place
import type Test from 'test'; // -> no changes

// use autocompletion -> no changes
const test = new Test();
```

Does this issue occur when all extensions are disabled?: Yes

- VS Code Version: 1.106.3
- OS Version: Linux x64 6.14.0-36-generic snap

Steps to Reproduce:

1. Make new project
2. Add `tsconfig.json`
3. Specify `"verbatimModuleSyntax": true` in the `tsconfig.json`
4. Add new file `test.ts`
```ts
export class Test {}
```
5. Add new file `example.ts`
```ts
const test: Test;
// use autocompletion on the "Test"
```
6. Observe that `import type` has been added
```ts
import type { Test } from 'test';

const test: Test;
```
7. Try to create new `Test` instance
```ts
import type { Test } from 'test';

const test: Test = new Test();
```
8. Observe error
```ts
`'Test' cannot be used as a value because it was imported using 'import type'.ts(1361)`
```
9. Use autocomplete on the `Test`, observe that `import type Test from 'test'` has NOT been changed to `import Test from 'test'`

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema usando tsconfig.json con verbatimModuleSyntax, test.ts che esporta Test ed example.ts come mostrato; esegui i passaggi del completamento automatico e conferma che il tipo di import rimanga. Traccia il punto di ingresso di TypeScript coinvolto nel completamento automatico o nella modifica degli import, quindi verifica che l'uso di Test come valore rimuova il tipo, mentre l'uso esclusivamente come tipo lo mantenga.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
developer-experience, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.