Bun TypeScript Support
Bun has native TypeScript support, allowing you to run .ts and .tsx files directly without any configuration. This chapter introduces Bun's TypeScript features and best practices.
Out of the Box
Running TypeScript Directly
Run:
No need to:
- Install typescript
- Configure ts-node
- Pre-compilation step
TypeScript Configuration
Auto-generate tsconfig.json
Recommended Configuration
Bun Type Definitions
Get complete Bun API type hints:
Type Checking
Running Type Checks
Bun runtime does not perform type checking (for speed), you need to run it separately:
Type Error Example
TSX / JSX Support
React Components
Server-Side Rendering
JSX Configuration
Type Imports
Importing Types
Inline Type Imports
Generics
Generic Functions
Generic Classes
Generic Interfaces
Decorators
Enabling Decorators
Class Decorators
Method Decorators
Utility Types
Common Utility Types
Custom Utility Types
Type Guards
Type Guard Functions
in Operator
Building TypeScript Projects
Compilation Output
Complete Build Process
Summary
This chapter introduced:
- ✅ Bun's native TypeScript support
- ✅ tsconfig.json configuration
- ✅ TSX/JSX support
- ✅ Type checking and type imports
- ✅ Generics and decorators
- ✅ Utility types and type guards
- ✅ Building TypeScript projects
Next Steps
Continue reading Environment Variables to learn about Bun's environment configuration management.