Subchapter 8.15
references/option-dts.mdMarkdown5 KBView on GitHub
tsdown uses rolldown-plugin-dts (opens in a new tab) to generate and bundle TypeScript declaration files.
Requirements:
DTS generation is automatically enabled if package.json contains:
types field, ortypings fieldtsdown --dtsexport default defineConfig({
dts: true,
})Extremely fast - uses oxc-transform for generation.
// tsconfig.json
{
"compilerOptions": {
"isolatedDeclarations": true
}
}Falls back to TypeScript compiler. Reliable but slower.
Map .d.ts files back to original .ts sources (useful for monorepos).
{
"compilerOptions": {
"declarationMap": true
}
}export default defineConfig({
dts: {
sourcemap: true,
},
})Override TypeScript compiler options:
export default defineConfig({
dts: {
compilerOptions: {
removeComments: false,
},
},
}).js and .d.ts files generated in same build.d.ts filesexport default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
})Output:
dist/index.mjsdist/index.cjsdist/index.d.tsexport default defineConfig({
entry: {
index: 'src/index.ts',
utils: 'src/utils.ts',
},
format: ['esm', 'cjs'],
dts: true,
})Output:
dist/index.mjs, dist/index.cjs, dist/index.d.tsdist/utils.mjs, dist/utils.cjs, dist/utils.d.tsexport default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: {
sourcemap: true, // Enable declaration maps
},
})// tsconfig.json
{
"compilerOptions": {
"isolatedDeclarations": true,
"declaration": true,
"declarationMap": true
}
}// tsdown.config.ts
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true, // Will use fast oxc-transform
})Ensure TypeScript is installed:
pnpm add -D typescriptEnable isolatedDeclarations in tsconfig.json for faster builds.
Check that all exports have explicit types (required for isolatedDeclarations).
For DTS-specific issues, report to rolldown-plugin-dts (opens in a new tab).
Enable Vue component type generation (requires vue-tsc):
export default defineConfig({
dts: {
vue: true,
},
})Control Oxc usage for declaration generation:
export default defineConfig({
dts: {
oxc: true, // Use oxc-transform (fast, requires isolatedDeclarations)
},
})Specify a different tsconfig for DTS generation:
export default defineConfig({
dts: {
tsconfig: './tsconfig.build.json',
},
})| Option | Type | Description |
|---|---|---|
sourcemap | boolean | Generate declaration source maps |
compilerOptions | object | Override TypeScript compiler options |
vue | boolean | Enable Vue type generation (requires vue-tsc) |
oxc | boolean | Use oxc-transform for fast generation |
tsconfig | string | Path to tsconfig file |
resolver | 'oxc' | 'tsc' | Module resolver: 'oxc' (default, fast) or 'tsc' (more compatible) |
cjsDefault | boolean | CJS default export handling |
sideEffects | boolean | Preserve side effects in declarations |