[suggestions] Provide import suggestions for imports from package.json "imports" field #49492
Closed
5 tasks done
Labels
Domain: Auto-import
Experience Enhancement
Noncontroversial enhancements
Fix Available
A PR has been opened for this issue
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
Suggestion
π Search Terms
imports, suggestions, nodenext
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
So in Node's esm there is the
"imports"
field which allows aliasing or overriding dependencies based on a host.It would be nice if TS would suggest these when providing import suggestions, i.e. currently when imports are suggested only the original paths are revealed:
However there is a
{ "imports": { "#base64": "./lib/Base64.js" } }
entry inpackage.json
, it would be nice if this would be suggested.(I made the above as a small example here to demonstrate).
π» Use Cases
Basically anywhere that people are using
"imports"
they probably want suggestions from"imports"
. In fact I'd say that these suggestions should probably come above all other import suggestions (particularly in cases where an"imports"
entry and other specifier resolve to thesame module). Why? Well if people are putting things like conditional imports:
Then people would most likely want the version that can be used in either environment rather than the more specific implementations of
node:assert
or./lib/browserFs.js
(otherwise why would they have bothered having the"imports"
to begin with?).This is true for basic aliases as well, if someone puts an alias in
"imports"
like my above example, then they presumably want the alias to be the preferred way to import such a file not the original path.The text was updated successfully, but these errors were encountered: