Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
richardszalay opened this issue Aug 9, 2018 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@richardszalay
Copy link

richardszalay commented Aug 9, 2018

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 [email protected] 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 (?)

@ghost ghost added Bug A bug in TypeScript Fixed A PR has been merged for this issue labels Aug 10, 2018
@RyanCavanaugh RyanCavanaugh assigned ghost Aug 10, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 10, 2018
@ghost
Copy link

ghost commented Sep 4, 2018

Should be fixed by #25803.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants