TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open Friend-LGA opened this issue 1 month ago • 1 comments

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'

Friend-LGA avatar Dec 11 '25 16:12 Friend-LGA

Thanks for creating this issue! It looks like you may be using an old version of VS Code; the latest stable release is 1.107.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

I don't think this is a regression; AFAIK we've never had the feature to promote type-only import to value import on completion. But it'd be a nice change to do.

RyanCavanaugh avatar Dec 12 '25 18:12 RyanCavanaugh