Skip to content

VSCode never offers a (shorter) relative import path when the module matches compilerOptions.paths #26348

Closed
@richardszalay

Description

@richardszalay

Issue Type: Bug

The typescript.preferences.importModuleSpecifier setting states that using auto will "infer the shortest path type". However, when a compilerOptions.paths value matches the import, only a full path is offered even if it is longer than the relative one. Oddly, this appears to the be opposite of #25876

(What would actually be nice is to configure the number of parent directories / ../ before preferring an absolute path)

  1. Set the workpace typescript.preferences.importModuleSpecifier setting to auto

  2. Add typescript@3.0.1 and configure the workspace to use it

  3. Create the following structure:

tsconfig.ts
src/
  features/
    feature1/
      file1.ts
      file2.ts
// tsconfig.ts
{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "features/*": ["features/*"]
    }
}
// file2.ts
export interface ExportedInterface {
}
  1. In file1.ts, reference ExportedInterface and use the "Quick Fix" to add an import.

Expected:

import { ExportedInterface } from './file2'

Actual:

import { ExportedInterface } from './features/feature/file2'

VS Code version: Code 1.25.1 (1dfc5e557209371715f655691b1235b6b26a06be, 2018-07-11T15:43:11.471Z)
OS version: Windows_NT ia32 10.0.17134

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz (4 x 2496)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 15.93GB (5.70GB free)
Process Argv C:\Program Files (x86)\Microsoft VS Code\Code.exe .
Screen Reader no
VM 0%

Related Issues:

#25876 appears to be the opposite (?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions