Profile
Back to NewsBack
GitHub Trending 10 min
Reader Mode
stacksjs/dtsx: ⚡ Extremely fast, smart & configurable DTS emitter.

stacksjs/dtsx: ⚡ Extremely fast, smart & configurable DTS emitter.

4 hours ago

Social Card of this repo

npm version</a> GitHub Actions</a> Commitizen friendly</a>

dtsx

Extremely fast, smart .d.ts generation with sound type inference & @defaultValue preservation.

Features

  • 🎯 Sound type inference with @defaultValue preservation
  • ⚡ Extremely fast .d.ts generation
  • 🤖 Cross-platform binary _(Zig native + Bun)_
  • 🔄 Parallel processing support
  • 📥 Stdin/stdout support for piping
  • 👀 Watch mode for development
  • ⚙️ Highly configurable
  • ✅ Built-in validation
[!NOTE]
dtsx works out of the box without isolatedDeclarations — it infers narrow types directly from your source values. That said, enabling isolatedDeclarations is still a good idea as it enforces explicit type annotations at module boundaries, encouraging better type hygiene across your codebase. When enabled, dtsx treats annotations as authoritative, skips initializers for concrete types, and only reads broad containers to preserve @defaultValue documentation.

Install

bun install -d @stacksjs/dtsx
[email protected], please allow us to use the dtsx package name 🙏_

Usage

There are two ways to use dtsx: _as a library or as a CLI._ Both work out of the box — no isolatedDeclarations required. dtsx infers narrow types directly from your source values. If you do enable isolatedDeclarations, dtsx uses it as a fast path to skip initializer parsing when explicit type annotations are present.

Library

import type { DtsGenerationOptions } from '@stacksjs/dtsx'
import { generate, processSource } from '@stacksjs/dtsx'

const options: DtsGenerationOptions = { cwd: './', // default: process.cwd() root: './src', // default: './src' entrypoints: ['*/.{ts,tsx,mts,cts,vue,stx}'], // default outdir: './dist', // default: './dist' clean: true, // default: false verbose: true, // default: false keepComments: true, // default: true parallel: true, // default: false - process files in parallel concurrency: 4, // default: 4 - number of concurrent workers dryRun: false, // default: false - preview without writing stats: true, // default: false - show generation statistics validate: true, // default: false - validate generated .d.ts files }

const stats = await generate(options) console.log(Generated ${stats.filesGenerated} files in ${stats.durationMs}ms)

// You can also process source code directly: const dtsContent = processSource( export const greeting: string = "Hello"; export function greet(name: string): string { return greeting + " " + name; } ) console.log(dtsContent) // Output: // export declare const greeting: string; // export declare function greet(name: string): string;

Entrypoints, include patterns, and relative re-exports share normalized native source paths. Overlapping matches generate each source once, including on Windows. With outputStructure: 'flat', nested sources emit directly into outdir; distinct sources with the same declaration filename fail before cleaning the previous declarations. Directory barrels and graph entrypoints use the same native path identity as discovered files, including absolute aliases containing .. segments.

STX Components

.stx files are declaration entrypoints alongside TypeScript and Vue files. dtsx reads Vue-style Chat with me