Course contentsShow
← TypeScript
Lesson 67 of 1,7962. Setup and ToolingFree lesson

tsx: A Faster Alternative to ts-node

tsx uses esbuild for near-instant transpilation, ideal for development and scripts.

tsx: A Faster Alternative to ts-node

What you'll learn: How tsx uses modern tooling to run TypeScript files instantly, making development faster and more pleasant.

The Speed Problem with ts-node

You've already learned that ts-node lets you run TypeScript directly without manually compiling first. But ts-node uses the official TypeScript compiler (tsc) under the hood, which can feel slow, especially as your project grows. Every time you run a script, there's a noticeable pause while it transpiles your code.

How tsx Solves This

tsx is a drop-in replacement for ts-node that uses esbuild instead of tsc for transpilation. Think of esbuild as a sports car compared to tsc's reliable sedan—both get you there, but esbuild is dramatically faster because it's written in Go (a compiled language) rather than TypeScript itself.

The key trade-off: esbuild focuses purely on transpilation (converting TypeScript to JavaScript) without doing type-checking. It strips out the types and runs your code immediately. This is perfect for development and running scripts where you want instant feedback.

When to Use tsx

Use tsx when you need:

  • Fast development iteration: Running scripts repeatedly during development
  • Quick prototyping: Testing ideas without compilation delays
  • Build scripts: Running utility scripts that don't need full type-checking

Install it with:

npm install -D tsx

Run your TypeScript files with:

tsx your-script.ts

Remember: tsx doesn't replace type-checking—you still need tsc --noEmit or your editor's TypeScript integration to catch type errors. It just makes running code faster.

Key Takeaway: tsx sacrifices type-checking for near-instant transpilation using esbuild, making it ideal for development and scripts where speed matters more than compile-time validation.