microsoft / microsoft/TypeScript

Allow to Override Import Paths For Auto-Import

Open
#45,065 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

IDisposable, Emitter and Event are very common types in the VS Code codebase.
Unfortunately, you have to be very careful when importing them through autocomplete.
Even worse, sometimes all the places to import from are suggested except the correct one.

In 99% of cases, we are importing IDisposable from vs/base/common/lifecycle. As you can see here, TypeScripts suggests all places except the right one:

image

It would be very practical if one could override where to import unresolved symbols from.
E.g.

"typescript.importFromOverrides": {
  "src/vs/editor/**": {
    "IDisposable": "vs/base/common/lifecycle",
    "Event": "vs/base/common/events"
  }
}

Alternatively, TypeScript could figure out where the Symbol has been imported from in adjacent files.
Maybe a disallow-list would also make sense (never import IDisposable from node-pty, or never import anything from vs/workbench/workbench.web.api).

This is now the second codebase where I ran into the permanent problem of importing a common symbol from a wrong module, which makes me believe this is a common problem.
I run into this problem one to ten times per day.

Here is another example:
image
We never want to import from vscode.
Being able to customize the preferred import would be a huge deal (especially for the quickfix "add all missing imports").

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

Reproduce the reported auto-import and quick-fix behavior in the VS Code codebase using symbols such as IDisposable, Emitter, and Event. Compare the suggested modules with the preferred import paths in the examples; done should mean the requested import preference or exclusion behavior is supported and works for adding missing imports.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.