microsoft / microsoft/TypeScript

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

未关闭
#62,882 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Experience Enhancement Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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'`

贡献指南

打开贡献指南

调研方向

使用带有 verbatimModuleSyntax 的 tsconfig.json、导出 Test 的 test.ts 以及如图所示的 example.ts 重现该问题;执行自动补全步骤,并确认 import type 仍然存在。跟踪涉及自动补全或导入编辑的 TypeScript 入口点,然后验证将 Test 用作值会移除 type,而仅用于类型时会保留它。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
developer-experience, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。