microsoft / microsoft/TypeScript
Autocompletion does NOT remove `type` from `import type` when needed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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'`
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit tsconfig.json mit verbatimModuleSyntax, test.ts, das Test exportiert, und example.ts wie gezeigt; führe die Schritte für die Autovervollständigung aus und bestätige, dass der Importtyp erhalten bleibt. Verfolge den beteiligten TypeScript-Einstiegspunkt für die Autovervollständigung oder Importbearbeitung und überprüfe anschließend, dass die Verwendung von Test als Wert den Typ entfernt, während eine reine Typverwendung ihn beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- developer-experience, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100