JSPM

  • Created
  • Published
  • Downloads 1049977
  • Score
    100M100P100Q209518F
  • License LGPL-3.0

An experiment to generate .d.ts rollup files

Package Exports

  • rollup-plugin-dts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-dts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rollup-plugin-dts

This is an EXPERIMENT to generate roll-upd .d.ts definition files from your .ts files.

Why?

Well, ideally TypeScript should just do that itself, and it also has a proposal to do that. But since ~3 years, it hasn’t happened yet.

There are also some solutions for this already:

  • API Extractor an official Microsoft project, which however is super complicated and I was not able to get it to work.
  • dts-bundle-generator which was a good inspiration for this project but in the end didn’t really work as well for my use-cases.

Some projects, like rollup itself go the route of completely separating their public interfaces in a separate file.

Does it even work?

Well yes it does, even though I am sure there are a lot of things I haven’t covered yet. However, so far it is complete enough to even generate its own definition file

How does it work?

This project abuses the internals implementation of rollup in a quite interesting way. See, rollup uses string manipulation to generate its output file, by changing and removing parts of the input file content. It also does quite extensive dead code elimination by walking the AST of the input code and figuring out which parts it can safely remove from the output bundle.

We can use this knowledge to specifically direct rollup to keep, change and remove parts of our input file.

TODO

  • explain how I abuse rollup to do what I want :-D

Things to test:

  • export default
  • function arguments
  • function return values
  • make sure overrides work correctly
  • make sure tsdoc and other type of comments work correctly

Things to implement:

  • classes
  • maybe removing things from the bundle marked with @internal or @hidden