Course contentsShow
← TypeScript
Lesson 1232 of 1,79629. The Build PipelineFree lesson

tsc Output: Per-File Transpilation

Understand how tsc emits one .js file per .ts file, preserving your source structure without bundling.

tsc Output: Per-File Transpilation

What you'll learn: How the TypeScript compiler transforms each .ts file into a corresponding .js file while preserving your project's directory structure.

The Core Idea

When tsc compiles your TypeScript code, it operates on a per-file basis by default. This means every .ts source file becomes its own separate .js file in the output directory. The compiler does not bundle your code together — it simply translates TypeScript to JavaScript while maintaining your original file organization.

Think of it like translating a book chapter-by-chapter: each chapter gets its own translated version, and the structure of chapters remains identical in the translated edition.

How It Works

If your project looks like this:

src/
  utils/
    logger.ts
    math.ts
  index.ts

After running tsc with outDir set to dist, you'll get:

dist/
  utils/
    logger.js
    math.js
  index.js

Every TypeScript file has been transpiled to JavaScript, preserving the exact folder hierarchy. Your imports, directory nesting, and file naming all stay intact — only the extensions and content change.

Why Per-File Transpilation?

This approach keeps things simple and predictable:

  • Source map alignment: Each .js file maps directly to its .ts source
  • Incremental compilation: Only changed files need recompilation
  • Debugging clarity: File names and paths match between source and output
  • Module system preservation: Your import/export statements remain as-is

The compiler doesn't attempt to combine files, optimize across modules, or tree-shake — that's the job of bundlers like Webpack or Vite when you need it.

Key Takeaway: The TypeScript compiler performs one-to-one file transpilation, converting each .ts file to a corresponding .js file without bundling, maintaining your source directory structure in the output.