A Babel plugin that generates TypeScript declaration (.d.ts) files from JavaScript code with JSDoc type annotations. Version 0.6.3 is the latest stable release; the project appears to be in maintenance mode with no recent activity. It specializes in converting Babel-parsed ASTs into TypeScript declarations, supporting features like object parameters, this-type annotations, typeof-type annotations, and string literal types. Key differentiators include integration with Babel's transformation pipeline and suppression of private exports for clean typings.
npm install babel-dts-generatorVerified import paths — ran on the pinned version, not inferred.
Shows how to use babel-dts-generator as a Babel plugin to generate a .d.ts file from a source file with JSDoc annotations.
Add explicit type annotations to parameters that should be required, or update code to handle optional parameters
Ensure you have babel-core@^6.x installed, not @babel/core
Consider alternatives like tsc or @babel/preset-typescript for generating .d.ts files
Verify the 'output' option points to a folder; plugin generates .d.ts for each file but may require additional config
If you need _-prefixed exports in .d.ts, adjust the 'suppressPrivate' option (not documented)
Always await or use .then() when calling babel.transform() with this plugin
Install regenerator-runtime and require('regenerator-runtime/runtime') at your entry pointRun npm install babel-core@^6.0.0 --save-dev
Use const generator = require('babel-dts-generator').default; in CommonJS