Description
Suggestion
π Search Terms
imports, suggestions, nodenext
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β 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 in package.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 the
same module). Why? Well if people are putting things like conditional imports:
{
"imports": {
"#assert": {
"node": "node:assert",
"browser": "./lib/browserFs.js"
}
}
}
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.