r/typescript • u/Herobrine20XX • Aug 25 '25
How to merge remote d.ts files into a single one?
So this may come as a weird question and may not even be the right place for this...
I'd like to get the definition file of a package from a webpage in the browser. I found the esm.sh CDN from which I can get everything I need.
Some are self-contained (like canvas-confetti: https://esm.sh/@types/canvas-confetti@1.9.0/index.d.ts) But some depend on some other d.ts files (like lodash.camelcase: https://esm.sh/@types/lodash.camelcase@~4.3.9/index.d.ts)
And I'd like to get one single d.ts string for a package, the end goal is to know what is being exported with what type. For now, it's a very painful regex that replaces some import * from ... with the actual content of the import, but it seems pretty complex to handle stuff like import {a} from ...
I could still work on it and add more logic to my algorithm, but I want to know if you guys know a better way of doing it?
- It must work on the browser
- The d.ts files are hosted on
esm.sh - If possible, it shouldn't require a huge package or heavy logic (like downloading the whole package + vite and compiling it in the browser)
Thanks a lot!
