Registry / serialization / babel-dts-generator

babel-dts-generator

JSON →
library0.6.3jsnpmunverified

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-generator
INSTALL
IMPORT
SIG · BABEL-DTS-GENERATO
B
babel-dts-generator
serializationjavascriptv0.6.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import generator from 'babel-dts-generator'
const generator = require('babel-dts-generator').default
Default export is a function; CommonJS users must use require().default
generate
import { generate } from 'babel-dts-generator'
Named export for programmatic generation, distinct from default
BabelDtsGeneratorOptions
import type { BabelDtsGeneratorOptions } from 'babel-dts-generator'
import { BabelDtsGeneratorOptions } from 'babel-dts-generator'
Type import only; do not use at runtime

Shows how to use babel-dts-generator as a Babel plugin to generate a .d.ts file from a source file with JSDoc annotations.

import generator from 'babel-dts-generator'; import * as babel from 'babel-core'; const code = ` /** @param {number} a */ function foo(a) { return a; } `; babel.transform(code, { plugins: [ [generator, { output: 'dist/types', suppressExcess: true, suppressAmbientDeclaration: true }] ] }).then(result => { console.log(result.code); // .d.ts content }).catch(err => console.error(err));
Debug
Known issues
breakingUntyped parameters now treated as optional (since v0.5.0)
fix
Add explicit type annotations to parameters that should be required, or update code to handle optional parameters
affects: >=0.5.0
gotchaRequires babel-core (not @babel/core) due to legacy Babel 6 plugin API
fix
Ensure you have babel-core@^6.x installed, not @babel/core
affects: >=0.1.0
deprecatedThe project has not been updated since 2017 and may not work with modern Babel versions
fix
Consider alternatives like tsc or @babel/preset-typescript for generating .d.ts files
affects: >0.6.3
gotchaSupports only default exports? Check configuration for named exports
fix
Verify the 'output' option points to a folder; plugin generates .d.ts for each file but may require additional config
affects: >=0.1.0
breakingPrivate exports (prefixed with _) are suppressed by default since v0.6.0
fix
If you need _-prefixed exports in .d.ts, adjust the 'suppressPrivate' option (not documented)
affects: >=0.6.0
gotchaGenerator yields a Promise, not synchronous result
fix
Always await or use .then() when calling babel.transform() with this plugin
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: regeneratorRuntime is not defined
Async/await usage without regenerator runtime polyfill
fix
Install regenerator-runtime and require('regenerator-runtime/runtime') at your entry point
Cannot find module 'babel-core'
babel-core not installed or wrong version (needs v6)
fix
Run npm install babel-core@^6.0.0 --save-dev
TypeError: generator is not a function
Using default import incorrectly with CommonJS require
fix
Use const generator = require('babel-dts-generator').default; in CommonJS
Upgrade
Version history
0.6.3latest on npm
Audit
Dependencies
babel-corerequiredWorks as a Babel plugin; requires a compatible Babel version
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
babel-dts-generator — npm install babel-dts-generator · libregistry