Quick Start
Run TypeScript files directly:Run TypeScript
tsc, no ts-node, no configuration needed.
Features
Zero Config
Works out of the box without tsconfig.json
Fast Transpilation
Written in Zig for maximum performance
Source Maps
Accurate source maps for debugging
Path Mapping
Respects tsconfig paths automatically
How It Works
Bun’s TypeScript transpiler:- Strips type annotations - Removes TypeScript syntax
- Preserves runtime behavior - No type checking or validation
- Generates source maps - Maps back to original TypeScript
- Caches output - Hashes input to avoid re-transpiling
Supported TypeScript Features
Type Annotations
All type annotations are removed:Type annotations
Enums
Enums are compiled to JavaScript objects:Enums
- Regular enums → JavaScript objects
- Const enums → Inlined values (optimized)
Namespaces
Namespaces are supported but discouraged (use ES modules):Namespaces
Decorators
Bun supports both experimental and standard decorators:Decorators
tsconfig.json
src/runtime.zig:203-204
Using Declarations
Explicit resource management (TC39 Stage 3):Using declarations
Import/Export Extensions
Bun supports TypeScript import extensions:Import extensions
tsconfig.json Support
Bun respectstsconfig.json configuration:
Path Mapping
tsconfig.json
Using path aliases
src/resolver/resolver.zig
Compiler Options
Bun honors thesetsconfig.json options:
Module Resolution
Module Resolution
moduleResolution- “node”, “bundler”, “node16”, “nodenext”baseUrl- Base directory for module resolutionpaths- Path mapping for importstypes- Type declaration packages to includetypeRoots- Directories containing type definitions
JSX Options
JSX Options
jsx- “react”, “react-jsx”, “react-jsxdev”, “preserve”jsxFactory- JSX factory function (default:React.createElement)jsxFragmentFactory- Fragment factory (default:React.Fragment)jsxImportSource- Import source for automatic runtime
Transpilation
Transpilation
experimentalDecorators- Enable legacy decoratorsemitDecoratorMetadata- Emit design-time metadatauseDefineForClassFields- Class field initializationimportsNotUsedAsValues- Preserve/remove imports
Module Interop
Module Interop
esModuleInterop- Enable default import interopallowSyntheticDefaultImports- Allow default imports from CommonJSresolveJsonModule- Allow importing .json files
Bun ignores type-checking options (
strict, noImplicitAny, etc.) as it doesn’t perform type checking.Runtime Transpiler Cache
Bun caches transpiled TypeScript to avoid repeated parsing: Cache location:- Linux:
~/.bun/install/cache/ - macOS:
~/Library/Caches/Bun/ - Windows:
%LOCALAPPDATA%\Bun\Cache\
- File content changes (hash-based)
tsconfig.jsonmodifications- Bun version updates
src/runtime.zig:210 - Runtime transpiler cache
Disable Cache
Disable cache
Type Checking
Bun focuses on execution, not type checking. For type validation:Using TypeScript Compiler
Type checking
Package.json Scripts
package.json
IDE Integration
Recommended setup:- VS Code - Install TypeScript extension
- Configure workspace:
.vscode/settings.json
CommonJS & ESM Interop
Bun seamlessly handles TypeScript with both module systems:ES Modules (.ts, .mts)
ESM TypeScript
CommonJS (.cts)
CommonJS TypeScript
Type Imports
Type-only imports
Declaration Files (.d.ts)
Bun recognizes TypeScript declaration files:Declaration files
Debugging TypeScript
Bun generates source maps for accurate debugging:VS Code Launch Config
.vscode/launch.json
Performance
Bun’s TypeScript transpiler is significantly faster thantsc or ts-node:
- Written in Zig: Native code, no JavaScript overhead
- Parallel parsing: Multi-threaded for large projects
- Lazy transpilation: Only transpiles imported files
- Efficient caching: Hash-based cache invalidation
| Tool | Time |
|---|---|
| Bun | ~0.5s |
| esbuild | ~2s |
| tsc | ~15s |
| ts-node | ~30s |
Benchmarks approximate, actual performance depends on code complexity.
Implementation Details
TypeScript transpilation implementation:- Parser:
src/js_parser.zig- Parses TypeScript AST - Printer:
src/js_printer.zig- Generates JavaScript - Transpiler:
src/transpiler.zig- Orchestrates parsing/printing - Runtime features:
src/runtime.zig:144-327- Feature flags and configuration
Limitations
Troubleshooting
Module Resolution Issues
Check resolution
Path Mapping Not Working
Ensuretsconfig.json is in the project root:
Related
- Loaders - File type handling
- JSX - JSX/TSX configuration
- Modules - Module resolution
- Watch Mode - Auto-reload on changes