Skip to content

Automatically added TypeScript import on save is incorrectly type import #62319

@ulrichstark

Description

@ulrichstark

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.103.2
  • OS Version: Darwin arm64 24.6.0

Steps to Reproduce:

  1. git clone https://github.com/ulrichstark/vscode-type-import-repro.git
  2. code vscode-type-import-repro --disable-extensions
  3. open file a.ts by double clicking
  4. open file b.ts by double clicking
  5. save file b.ts
  6. import type { helloWorld } from "./a"; gets automatically added into file b.ts

Files of repro project:

.vscode/settings.json

{
    "editor.codeActionsOnSave": {
        "source.addMissingImports.ts": "explicit"
    },
    "typescript.preferences.preferTypeOnlyAutoImports": true
}

a.ts

export function helloWorld() {
    console.log("Hello World!");
}

b.ts

if (true) {
    helloWorld();
}

helloWorld();

Results

function helloWorld is imported as type resulting in error:

'helloWorld' cannot be used as a value because it was imported using 'import type'.

Actual

import type { helloWorld } from "./a";

if (true) {
    helloWorld();
}

helloWorld();

Expected

import { helloWorld } from "./a";

if (true) {
    helloWorld();
}

helloWorld();

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions