microsoft / microsoft/TypeScript

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

Open
#62,882 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using tsconfig.json with verbatimModuleSyntax, test.ts exporting Test, and example.ts as shown; run the autocomplete steps and confirm the import type remains. Trace the TypeScript autocomplete or import-editing entry point involved, then verify that using Test as a value removes type while type-only usage keeps it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.