{"id":18987,"library":"babel-dts-generator","title":"babel-dts-generator","description":"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.","status":"maintenance","version":"0.6.3","language":"javascript","source_language":"en","source_url":"https://github.com/YoloDev/babel-dts-generator","tags":["javascript","aurelia","babel","dts"],"install":[{"cmd":"npm install babel-dts-generator","lang":"bash","label":"npm"},{"cmd":"yarn add babel-dts-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-dts-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Works as a Babel plugin; requires a compatible Babel version","package":"babel-core","optional":false}],"imports":[{"note":"Default export is a function; CommonJS users must use require().default","wrong":"const generator = require('babel-dts-generator').default","symbol":"default","correct":"import generator from 'babel-dts-generator'"},{"note":"Named export for programmatic generation, distinct from default","symbol":"generate","correct":"import { generate } from 'babel-dts-generator'"},{"note":"Type import only; do not use at runtime","wrong":"import { BabelDtsGeneratorOptions } from 'babel-dts-generator'","symbol":"BabelDtsGeneratorOptions","correct":"import type { BabelDtsGeneratorOptions } from 'babel-dts-generator'"}],"quickstart":{"code":"import generator from 'babel-dts-generator';\nimport * as babel from 'babel-core';\n\nconst code = `\n/** @param {number} a */\nfunction foo(a) { return a; }\n`;\n\nbabel.transform(code, {\n  plugins: [\n    [generator, {\n      output: 'dist/types',\n      suppressExcess: true,\n      suppressAmbientDeclaration: true\n    }]\n  ]\n}).then(result => {\n  console.log(result.code); // .d.ts content\n}).catch(err => console.error(err));","lang":"javascript","description":"Shows how to use babel-dts-generator as a Babel plugin to generate a .d.ts file from a source file with JSDoc annotations."},"warnings":[{"fix":"Add explicit type annotations to parameters that should be required, or update code to handle optional parameters","message":"Untyped parameters now treated as optional (since v0.5.0)","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Ensure you have babel-core@^6.x installed, not @babel/core","message":"Requires babel-core (not @babel/core) due to legacy Babel 6 plugin API","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider alternatives like tsc or @babel/preset-typescript for generating .d.ts files","message":"The project has not been updated since 2017 and may not work with modern Babel versions","severity":"deprecated","affected_versions":">0.6.3"},{"fix":"Verify the 'output' option points to a folder; plugin generates .d.ts for each file but may require additional config","message":"Supports only default exports? Check configuration for named exports","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"If you need _-prefixed exports in .d.ts, adjust the 'suppressPrivate' option (not documented)","message":"Private exports (prefixed with _) are suppressed by default since v0.6.0","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Always await or use .then() when calling babel.transform() with this plugin","message":"Generator yields a Promise, not synchronous result","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install regenerator-runtime and require('regenerator-runtime/runtime') at your entry point","cause":"Async/await usage without regenerator runtime polyfill","error":"ReferenceError: regeneratorRuntime is not defined"},{"fix":"Run npm install babel-core@^6.0.0 --save-dev","cause":"babel-core not installed or wrong version (needs v6)","error":"Cannot find module 'babel-core'"},{"fix":"Use const generator = require('babel-dts-generator').default; in CommonJS","cause":"Using default import incorrectly with CommonJS require","error":"TypeError: generator is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}