How It Works
Bunli scans your commands directory and generates.bunli/commands.gen.ts with type definitions:
Configuration
Configure type generation inbunli.config.ts:
packages/core/src/config.ts:29-49
Generator Architecture
The generator follows this flow:packages/generator/src/generator.ts:30-93
Manual Type Generation
Run type generation explicitly:packages/cli/src/commands/generate.ts, packages/cli/src/commands/build.ts:112-126
Type Generation Example
Given these commands:Type-Safe Execution
The generated types enable autocomplete and validation:packages/core/src/cli.ts:731-779
Nested Commands
Type generation works with command groups:packages/core/src/cli.ts:733-734
Generated Store Types
Plugin stores are also type-safe:packages/core/src/generated.ts, packages/core/src/types.ts:206-211
Build Integration
Type generation runs automatically during builds:packages/cli/src/commands/build.ts:112-126
Development Workflow
Types regenerate automatically in dev mode:packages/cli/src/commands/dev.ts
Diagnostic Report
Enable detailed generation reports:packages/generator/src/generator.ts:72-89
Command Scanning
The scanner finds command files:packages/generator/src/scanner.ts
Troubleshooting
Types not updating
Types not updating
Run
bunli generate manually to regenerate types. Check that commands.entry points to the correct file.Commands not found in generated types
Commands not found in generated types
Ensure your command uses
name: 'commandName' as const for type inference. Check the diagnostic report for parsing errors.Type errors in generated file
Type errors in generated file
Make sure all commands export a default
defineCommand(). Verify that Zod schemas are properly typed.IntelliSense not working
IntelliSense not working
Restart your TypeScript server (VS Code: Cmd+Shift+P → “TypeScript: Restart TS Server”). Ensure
.bunli/commands.gen.ts exists.Testing Generated Types
Best Practices
Always use 'as const' on command names
Always use 'as const' on command names
This enables proper type inference:
Keep commands in a single directory
Keep commands in a single directory
Makes scanning and generation more reliable:
Export default from command files
Export default from command files
The generator expects default exports:
Enable generateReport during development
Enable generateReport during development
Helps debug type generation issues:
Next Steps
Defining Commands
Learn how to define commands with proper type inference
Working with Options
Master Zod schemas for type-safe options
Building Binaries
Compile your type-safe CLI to executables
Command Groups
Type generation for nested command structures