Native Zig Transpiler: Running .ts and .jsx with Zero Build Step
- Last updated
- Prerequisites:
- TypeScript compiler (`tsc`)
- JSX transpilation
- bun
- typescript
- jsx
- transpiler
- zig
- developer-experience
Read at your depth
The practical view
Bun natively executes `.ts`, `.tsx`, `.js`, and `.jsx` files without any build step, loader, or compilation script. When you run `bun run index.ts`, Bun parses and strips TypeScript types on the fly in memory and sends the bytecode directly to JavaScriptCore. JSX is transformed into `React.createElement` or modern JSX runtime (`jsx-dev`) calls automatically.
The same idea in other frameworks
`ts-node` / `tsx` / `esbuild-register` wrappers for running TypeScript files.Deno built-in TypeScript engine (using SWC).`bun run file.ts` (native Zig type-stripping transpiler).Babel / SWC build-time compilation.Legacy vs modern
Node.js ts-node Overhead vs Native Bun TypeScript Execution
Node requires third-party transpilers with startup lag; Bun executes `.ts` and `.tsx` natively in milliseconds.
npx ts-node app.ts // ❌ 1-2 second startup latency for type compilationbun app.ts // ✅ NEW: Instant execution with zero dependenciesInterview gotchas
Context
This is a fundamental question regarding how fast TypeScript runtimes operate.
The mechanical answer
**No, Bun does not type-check your code at runtime.** Bun's transpiler is a pure type stripper: it removes type annotations and executes the remaining JavaScript code directly. If your code has a TypeScript type mismatch (e.g. assigning a number to a string type), Bun will still execute it without error. To enforce type safety, run `tsc --noEmit` in your CI/CD pipeline.
Trap
Never assume that code running under Bun is type-safe without running `tsc --noEmit` in your test/lint scripts.
Context
Checks knowledge of compiler configuration via `tsconfig.json` in Bun.
The mechanical answer
Bun reads your `tsconfig.json` or `jsconfig.json`. You configure JSX compilation via the `compilerOptions.jsx` and `compilerOptions.jsxImportSource` fields: for React 19 (`"jsx": "react-jsx"`), for Preact (`"jsxImportSource": "preact"`), or for custom factories (`"jsxFactory": "h"`).
Trap
If no `tsconfig.json` is present, Bun defaults to standard `react-jsx` (React 17+ automatic JSX runtime).