Package Exports
- @stacksjs/dtsx
- @stacksjs/dtsx/bin/cli.js
- @stacksjs/dtsx/chunk-qsyn1k3w.js
- @stacksjs/dtsx/config.d.ts
- @stacksjs/dtsx/extractor.d.ts
- @stacksjs/dtsx/generator.d.ts
- @stacksjs/dtsx/index.d.ts
- @stacksjs/dtsx/parser.d.ts
- @stacksjs/dtsx/processor.d.ts
- @stacksjs/dtsx/src/index.js
- @stacksjs/dtsx/types.d.ts
- @stacksjs/dtsx/utils.d.ts
Readme

dtsx
A library that helps you generate TypeScript declaration files from your project. Given we do not know the user's input ever, we need to never hardcode based results based from our examples, always create a dynamic solution.
Features
- β‘ Extremely fast .d.ts generation
- βοΈ Highly configurable
- πͺΆ Lightweight library
- π€ Cross-platform binary
Install
bun install -d @stacksjs/dtsx@npmjs.com, please allow us to use the dtsx package name π
Get Started
There are two ways of using this ".d.ts generation" tool: as a library or as a CLI.
But before you get started, please ensure you enabled isolatedDeclarations in your tsconfig.json file.
{
"compilerOptions": {
"isolatedDeclarations": true
}
}Library
Given the npm package is installed, you can use the generate function to generate TypeScript declaration files from your project.
Usage
import type { DtsGenerationOptions } from '@stacksjs/dtsx'
import { generate } from '@stacksjs/dtsx'
const options: DtsGenerationOptions = {
cwd: './', // default: process.cwd()
root: './src', // default: './src'
entrypoints: ['**/*.ts'], // default: ['**/*.ts']
outdir: './dist', // default: './dist'
clean: true, // default: false
verbose: true, // default: false
keepComments: true, // default: true
}
await generate(options)Available options:
Library usage can also be configured using a dts.config.ts (or dts.config.js) file which is automatically loaded when running the ./dtsx (or bunx dtsx) command. It is also loaded when the generate function is called, unless custom options are provided.
// dts.config.ts (or dts.config.js)
export default {
cwd: './',
root: './src',
entrypoints: ['**/*.ts'],
outdir: './dist',
keepComments: true,
clean: true,
verbose: true,
}You may also run:
./dtsx generate
# if the package is installed, you can also run:
# bunx dtsx generateCLI
The dtsx CLI provides a simple way to generate TypeScript declaration files from your project. Here's how to use it:
Usage
Generate declaration files using the default options:
dtsx generateOr use custom options:
# Generate declarations for specific entry points:
dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types
# Generate declarations with custom configuration:
dtsx generate --root ./lib --outdir ./types --clean
dtsx --help
dtsx --versionAvailable options:
--cwd <path>: Set the current working directory (default: current directory)--root <path>: Specify the root directory of the project (default: './src')--entrypoints <files>: Define entry point files (comma-separated, default: '**/*.ts')--outdir <path>: Set the output directory for generated .d.ts files (default: './dist')--keep-comments: Keep comments in generated .d.ts files (default: true)--clean: Clean output directory before generation (default: false)--tsconfig <path>: Specify the path to tsconfig.json (default: 'tsconfig.json')--verbose: Enable verbose output (default: false)
To learn more, head over to the documentation.
Testing
bun testChangelog
Please see our releases page for more information on what has changed recently.
Contributing
Please review the Contributing Guide for details.
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Postcardware
βSoftware that is free, but hopes for a postcard.β We love receiving postcards from around the world showing where dtsx is being used! We showcase them on our website too.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States π
Sponsors
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
Made with π