Change declaration file import paths from .js
to .d.ts
#50629
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Domain: Declaration Emit
The issue relates to the emission of d.ts files
Suggestion
An idea for TypeScript
Suggestion
🔍 Search Terms
declaration import paths
esnext declaration import path
I also know there's a lot of somewhat-related conversation around this area in #37582 and #46452 , but this is only for the output of declaration files, so I'm not sure if it's exactly related to those issues or not. If it is, feel free to close this and accept my apologies.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
When using TypeScript to
emitDeclarationOnly
, it outputs a.d.ts
file. However, the contents of that file keep the same import path. An example:What would be nice, however, is to have the declaration file import paths point to the actual file, like so:
To maybe help see more clearly, I created this repo that has the current source code and output files when running
npx tsc --emitDeclarationOnly
. You'll note that the/types/index.d.ts
file has an import/export path to a file that doesn't actually exist, but is still found when using something like node's resolution algorithm.📃 Motivating Example
When using Deno, you can put up your library + types up on a CDN. However, Deno must have the exact path to the file in order for it to work. Unfortunately it seems that it means that the other declaration files cannot be found because the import path in the declaration file isn't exactly correct.
Unless I've missed something important about TS / Deno?
💻 Use Cases
I don't think this would have any effects on the ecosystem, would it? Is there a chance it would maybe even make things slightly faster when looking up types (even for node projects), because the declaration files are pointing directly to the correct file instead of having to go through the resolution algorithm? I'm not sure, I'll defer to you experts.
Thank you ❤️
The text was updated successfully, but these errors were encountered: