You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update path alias guides to mention subpath imports
#14878
The "Imports reference" page currently features a section on aliases which tells users how to set up import aliases using tsconfig.json. The "TypeScript configuration" page also includes a similar example.
One alternative to TypeScript import aliases is Node.js Subpath Imports, which are defined in package.json:
Subpath imports require using # instead of @ or ~. But they are natively supported and, unlike tsconfig.json, the aliases resolve properly in compiled .js without requiring special parsing. (tsconfig aliases can cause issues when paths are not resolved properly, and require more setup to use properly inside test files, Storybook, etc.)
Subpath imports also prevent conflicts with installed packages that can happen when using tsconfig and @ aliases, as a user reported in Discord.
On my own sites, I've moved away from using tsconfig.json for path aliases, and now default to using subpath imports.
This thread is to discuss if it's worth updating the alias guides in the docs to offer subpath imports as an alternative to the tsconfig-based approach.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
The "Imports reference" page currently features a section on aliases which tells users how to set up import aliases using
tsconfig.json. The "TypeScript configuration" page also includes a similar example.One alternative to TypeScript import aliases is Node.js Subpath Imports, which are defined in
package.json:{ "name": "my-site", "imports": { "#*": [ "./src/*", "./src/*.ts", "./src/*.tsx", ] } }More info:
Subpath imports require using
#instead of@or~. But they are natively supported and, unliketsconfig.json, the aliases resolve properly in compiled.jswithout requiring special parsing. (tsconfigaliases can cause issues when paths are not resolved properly, and require more setup to use properly inside test files, Storybook, etc.)Subpath imports also prevent conflicts with installed packages that can happen when using
tsconfigand@aliases, as a user reported in Discord.On my own sites, I've moved away from using
tsconfig.jsonfor path aliases, and now default to using subpath imports.This thread is to discuss if it's worth updating the alias guides in the docs to offer subpath imports as an alternative to the
tsconfig-based approach.All reactions