KEMBAR78
Existing `import type` prevents autocompletion of value import for TypeScript · Issue #44804 · microsoft/TypeScript · GitHub
Skip to content

Existing import type prevents autocompletion of value import for TypeScript #44804

@lgarron

Description

@lgarron

Issue Type: Bug

Consider the following code:

// a.ts
import type { B } from "./b";
import { makeB } from "./b";
const variable: B = makeB();
// b.ts
export class B {}
export function makeB(): B { return new B(); }

Now type:

// new line in `a.ts`
new B

on a new line inside a.ts and try to autocomplete the import of B to use it as a constructor.

Expected behaviour

VSCode changes the import of B from a type import to a value import.

(It would be a syntax error to add the value import while keeping the type import, so the type import of B has to be removed at the same time. In this particular example, I would expect the entire import type line to be removed and the import of B added to the same line as makeB.)

Observed behaviour:

VSCode offers an autocompletion dropdown, but the default choice does nothing. There is no choice that will result in a value import of B unless the existing type import is deleted.

Screencap:

Screen.Recording.2021-06-29.at.01.47.40.mov

This is a frustrating experience: If I "happen" to autocomplete something as a value in a given file before I complete it as a type the first time, then autocomplete works naturally and the code is fine. But if I autocomplete something as a type the first time, then VSCode is unable to autocomplete the value import. Even though I know the issue and can work around it every time, autocomplete feels subjectively unreliable.

This kind of situation can be common in a large codebase with importsNotUsedAsValues. In particular, I'm working on a project where it is common to use a particular class (Alg from cubing/alg) as a the type of a variable in a given file, only to need the constructor later on.

VS Code version: Code 1.57.1 (507ce72a4466fbb27b715c3722558bb15afa9f48, 2021-06-17T13:28:32.912Z)
OS version: Darwin x64 20.5.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz (12 x 2900)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 5, 4
Memory (System) 32.00GB (1.37GB free)
Process Argv --disable-extensions --crash-reporter-id 35bab6a6-41b6-4e5f-9d55-05b4be8834fd
Screen Reader no
VM 0%
Extensions disabled
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30300192
pythontb:30283811
pythonvspyt551:30311712
vspre833:30321513
pythonptprofiler:30281270
vshan820:30294714
pythondataviewer:30285071
vscus158:30321503
pythonvsuse255:30323308
vscorehovct:30309550
vscod805cf:30301675
binariesv615:30325510
vsccppwtct:30329789

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions