microsoft / microsoft/TypeScript

Allow importModuleSpecifier: "relative" to be overridden for explicitly configured "paths" in a jsconfig/tsconfig

Open
#40,337 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

This is a follow-up issue of https://github.com/microsoft/TypeScript/issues/40139

As per the docs, once you've imported a variable somewhere, vscode knows where to find it (bypassing the issue above).

I want all my code to be imported with relative imports everywhere for consistency. so I set "javascript.preferences.importModuleSpecifier": "relative". However, I don't want relative paths to be used when importing from a module declared in tsconfig's paths, as I specifically put it there so it can be resolved as an absolute import for convenience.

Clearly these 2 settings are conflicting, but I wonder if the current compromise is the best one (i.e. settings.json wins over tsconfig)?

I would expect to be able to auto-import variables from my paths module absolutely, even though I want everything else to import relatively.

  • VSCode Version: Insiders
  • OS Version: macOS 10.15.6

Steps to Reproduce:

  1. Clone this repo: https://github.com/Floriferous/paths-resolution
  2. Go to branch absolute-import-paths
  3. Notice test2.js imports someVar properly
  4. Open test.js, try to auto-import someVar, notice intellisense only suggests a relative import

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the paths-resolution reproduction, especially test.js, test2.js, and the referenced jsconfig/tsconfig paths configuration; reproduce the auto-import suggestions with the relative preference enabled. Trace the auto-import handling for explicitly configured paths. Done means paths-based imports are suggested absolutely while other imports remain relative.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.