microsoft / microsoft/TypeScript

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

オープン
#62,882 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Experience Enhancement Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
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

// "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

// "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
    export class Test {}
    
  5. Add new file example.ts
    const test: Test;
    // use autocompletion on the "Test"
    
  6. Observe that import type has been added
    import type { Test } from 'test';
    
    const test: Test;
    
  7. Try to create new Test instance
    import type { Test } from 'test';
    
    const test: Test = new Test();
    
  8. Observe error
    `'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'

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

verbatimModuleSyntax を指定した tsconfig.json、Test を export する test.ts、および示されているとおりの example.ts を使って問題を再現し、オートコンプリートの手順を実行して import type が残ることを確認します。オートコンプリートまたは import の編集に関係する TypeScript のエントリーポイントを追跡し、その後、Test を値として使用すると type が削除され、型のみの使用では保持されることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
developer-experience, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。