Skip to content

TypeScript IntelliSense auto-import now overzealous, ignores relative path settings #46192

Closed
@CynicalBusiness

Description

@CynicalBusiness

Issue Type: Bug

Although TypeScript support is an extension, technically, I could not find a separate repository for it, so I'm submitting here as support is built-in. I can post elsewhere if this is the wrong place.

Since upgrading to 1.60, TypeScript IntelliSense has become very overzealous in wanting to use non-relative paths when auto-importing, to a point where auto-import is now completely unusable in my project. It seems the auto-import greatly prefers to use non-relative paths, particularly path aliases, whenever possible, completely ignoring my settings for relative-ity of auto-imports.

This issue appears on two separate VSCode installs, one on Windows 10 (this one) and one on Ubuntu 20.04.

Here's a setup with an example:

src/
  dirA/
    index.ts
    thing1A.ts
    thing2A.ts
  dirB/
    index.ts
    thing1B.ts
    thing2B.ts
  index.ts
tsconfig.json
package.json

The TSConfig has this:

{
  "compilerOptions": {
    "paths": {
      "~/*": ["src/*"]
    }
  },
  "include": ["src"]
}

And my index.ts in each directory has export * from "./thing1A" and export * from "./thing2A".

When editing thing1A.ts and attempting to auto-import modules:

  • From another package: uses package name ✔️
  • From dirA/thing2A.ts: uses ~/dirA ❌ (this should be ./thing2A)
  • From dirB/index.ts: uses ~/dirB ✔️
  • From dirB/thing1B.ts: uses ../dirB/thing1B ❌ (this would be the correct place for the ~, why does it do relative imports here!?)

It almost seems like some logic got inverted somewhere for deciding when to use path aliases.

I have also tried every possible option of javascript.preferences.importModuleSpecifier and typescript.preferences.importModuleSpecifier, but none of them are any different, including the new project-relative.

On the plus side, path aliases didn't work at all for me in 1.59, so this is nice to see it's been worked on.

VS Code version: Code 1.60.2 (7f6ab5485bbc008386c4386d08766667e155244e, 2021-09-22T12:00:31.514Z)
OS version: Windows_NT x64 10.0.19042
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (6 x 3192)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.92GB (13.34GB free)
Process Argv --crash-reporter-id 6012b397-c3f3-4e97-ac7e-0a2da3ad0fa6
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
pythonvspyt639:30300192
pythontb:30283811
pythonvspyt551:30345470
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30358480
pythondataviewer:30285071
pythonvsuse255:30340121
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
vsccppwtct:30364498
pythonvssor306:30344512
bridge0708:30335490
pygetstartedt2:30371810
dockerwalkthru:30370836
bridge0723:30353136
pythonrunftest32:30373476
pythonf5test824:30373475
javagetstartedc:30364665
pythonvspyt187:30373474
pydsgsc2:30361791
vsqsis200:30374795
vsaa593cf:30376535

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions