microsoft / microsoft/TypeScript
Autocompletion does NOT remove `type` from `import type` when needed
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
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'`
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện vấn đề bằng cách sử dụng tsconfig.json với verbatimModuleSyntax, test.ts export Test và example.ts như được minh họa; thực hiện các bước tự động hoàn thành và xác nhận rằng kiểu import vẫn còn. Truy vết điểm vào của TypeScript liên quan đến tính năng tự động hoàn thành hoặc chỉnh sửa import, sau đó xác minh rằng việc sử dụng Test như một giá trị sẽ loại bỏ kiểu, trong khi chỉ sử dụng như một kiểu thì giữ lại kiểu đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- developer-experience, tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100