Setting Up TypeScript: The Compiler, tsconfig, and Your Toolchain

A beginner-friendly guide to setting up TypeScript: installing the tsc compiler, understanding tsconfig.json, compiling .ts to .js, watch mode, and where TypeScript fits in a modern toolchain.

Published September 20, 20269 min readBy ACY Partner Indonesia
Setting Up TypeScript cover with a tsc command chip
300 × 250Ad Space AvailablePlace your ad here

So you’ve decided to give TypeScript a try. Good call. But the very first time most people sit down to actually use it, they hit a wall of unfamiliar words: compiler, tsc, tsconfig.json, build step, watch mode. None of it is hard once you see how the pieces fit together, but nobody is born knowing it.

This article walks you through that setup, slowly and from the ground up. We won’t tie ourselves to any particular editor, framework, or build tool. Instead, the goal is for you to understand what each part actually does, so that no matter what project you join later, the setup makes sense instead of feeling like magic.

Why TypeScript needs a setup step at all

Plain JavaScript runs directly. You hand a .js file to a browser or to a runtime like Node.js, and it runs. There’s no in-between.

TypeScript is different, and the reason is simple: browsers and runtimes don’t understand TypeScript. They only understand JavaScript. TypeScript is a layer you write on top of JavaScript that adds types — little labels that describe what kind of value something is (a number, a piece of text, a list of users, and so on). Those type labels are wonderful while you’re writing code, because they catch mistakes early. But they mean nothing to the machine that eventually runs the program.

So there has to be a step that takes your TypeScript and turns it into ordinary JavaScript. That step is called compiling (you’ll also hear “transpiling” — for our purposes treat them as the same thing). The tool that does it is the TypeScript compiler.

The one-sentence summary

TypeScript is what you write; JavaScript is what runs. The compiler is the bridge between the two.

Meet the compiler: tsc

The TypeScript compiler is a program called tsc (short for TypeScript compiler). Its job is to read your .ts files, check them for type errors, and write out matching .js files.

You install it through npm, the package manager that comes with Node.js. Most of the time you install it inside your project rather than globally on your whole computer, so that every project can pin its own version:

npm install --save-dev typescript

The --save-dev part means “this is a development tool, not something my app needs while running.” Once it’s installed, you can run the compiler:

npx tsc --version

npx is a small helper that runs a tool installed in your project. If it prints a version number, the compiler is ready.

Now imagine you have a tiny file called app.ts:

function greet(user: { name: string }): string {
  return "Hello, " + user.name;
}

const jane = { name: "Jane Doe" };
console.log(greet(jane));

Compile it:

npx tsc app.ts

The compiler reads app.ts, checks the types (here it confirms that greet is given an object with a name that is text), and produces app.js sitting right next to it. That app.js is plain JavaScript with the type labels stripped away — that’s the file you can actually run.

What compiling actually removes

It helps to see the before and after. The TypeScript above becomes roughly this JavaScript:

function greet(user) {
  return "Hello, " + user.name;
}

const jane = { name: "Jane Doe" };
console.log(greet(jane));

Notice what disappeared: the : { name: string } and the : string. Those were the types. They guided the compiler while it checked your work, and then they were erased, because the running program doesn’t need them. This is a key mental model — types exist at compile time, not at run time. They’re a safety net during development that gets folded away before the code ships.

The role of tsconfig.json

Running tsc app.ts by hand is fine for a single file. Real projects have dozens or hundreds of files, plus a pile of preferences: which JavaScript version to target, where to put the output, how strict to be about mistakes. Typing all of that on the command line every time would be miserable.

That’s what tsconfig.json is for. It’s a single configuration file that lives at the root of your project and tells the compiler how to behave. When you run tsc with no file name, the compiler looks for tsconfig.json, reads your preferences from it, and compiles the whole project accordingly.

You can generate a starter one:

npx tsc --init

A minimal, readable tsconfig.json might look like this:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true
  },
  "include": ["src"]
}

Let’s read it the way the compiler does:

Setting Plain-English meaning
target Which JavaScript version the output should match. Newer targets keep modern features; older ones convert them so they run on older environments.
module How import/export between files should be written in the output.
outDir Where compiled .js files should be written (here, a dist folder).
rootDir Where your source .ts files live (here, a src folder).
strict Turn on the full set of strict type checks. More on this below.
include Which folders the compiler should look in for source files.

The big idea: instead of describing the build every single time, you describe it once in tsconfig.json, and from then on a bare tsc command does the right thing.

Turn strict on early

The strict option switches on TypeScript’s most helpful checks at once. It feels demanding at first, but it’s far easier to start strict than to retrofit it later. New projects should keep strict: true.

Separating source from output

Notice how the config above keeps rootDir (src) and outDir (dist) apart. This is a habit worth forming. Your hand-written TypeScript lives in src. The compiler’s generated JavaScript lands in dist. You never edit files in dist by hand — they’re rebuilt from src every time you compile.

A typical layout looks like this:

my-project/
├─ src/
│  └─ app.ts        ← you write this
├─ dist/
│  └─ app.js        ← tsc generates this
├─ tsconfig.json    ← compiler settings
└─ package.json     ← project + dependencies

Keeping the two folders separate means your real work stays clean, and you can safely delete dist whenever you want — it’ll come right back on the next build. (It’s also common to tell version control to ignore dist entirely, since it can always be regenerated.)

Watch mode: compile as you type

Re-running tsc after every change gets old fast. The compiler has a built-in answer called watch mode. You start it once, and it keeps running, recompiling automatically the moment you save a file:

npx tsc --watch

Now the loop becomes: edit a file, save, and the compiler instantly rebuilds and re-checks everything. If you introduce a type error, it shows up in your terminal right away instead of waiting until you remember to compile. For day-to-day development this is the mode you’ll usually leave running in a corner of your screen.

Your editor is also checking

Modern editors run their own TypeScript check in the background, underlining errors as you type — independent of tsc. Watch mode and the editor complement each other: the editor gives instant feedback while you work, and tsc is the authoritative check that produces the actual output files.

Where TypeScript fits in a modern toolchain

Here’s where many beginners get confused, so let’s clear it up. In a small project, tsc does two jobs at once: it type-checks your code, and it produces the JavaScript output. Simple and self-contained.

But in larger or front-end projects, you’ll often see a different arrangement. A separate build tool (a bundler) handles turning your many files into the final assets the browser loads, and it does the TypeScript-to-JavaScript conversion as part of that process — usually by simply stripping the types out, very fast, without doing the type-checking.

That sounds contradictory until you separate the two responsibilities:

   What TypeScript gives you
   ┌─────────────────────────────┐
   │ 1. Type checking            │ ← catches mistakes (correctness)
   │ 2. Stripping types → JS     │ ← produces runnable code
   └─────────────────────────────┘

A modern toolchain frequently splits these:

  • The build tool / bundler takes care of step 2 quickly, so your app runs.
  • A separate tsc --noEmit run takes care of step 1, checking types without writing any output files (--noEmit means “check, but don’t produce JavaScript”).

That’s why you’ll sometimes see a project where tsc is configured not to emit files at all. It’s not broken — the build tool is doing the emitting, and tsc has been narrowed down to the one thing it’s best at: being the source of truth for type correctness.

Project shape Who converts TS → JS Who type-checks
Small / learning tsc tsc
Front-end app with a bundler the bundler tsc --noEmit (often in CI)
Node service with a runner a runtime loader or build step tsc --noEmit

You don’t need to memorize every variation. The thing to carry with you is the split: “make the code run” and “make sure the types are correct” are two separate jobs, and different tools can own them.

A clean starting point, start to finish

Putting it all together, a from-scratch setup for a small project is just a handful of steps:

# 1. Start a project
npm init -y

# 2. Add the TypeScript compiler as a dev tool
npm install --save-dev typescript

# 3. Create a tsconfig.json
npx tsc --init

# 4. Write code in src/, then compile
npx tsc

# 5. Or develop with auto-recompile
npx tsc --watch

From here you’d typically add a script to package.json so you can run npm run build instead of remembering the raw command — but that’s polish. The mental model underneath stays exactly the same.

Recap

TypeScript adds a small but real setup step, and now you know why and what each piece is doing:

  • TypeScript is for writing; JavaScript is for running. The compiler bridges them.
  • tsc is that compiler. You install it per-project with npm and run it with npx tsc.
  • Compiling checks your types and emits plain JavaScript, with the type labels removed. Types live at compile time, not run time.
  • tsconfig.json is the project’s settings file. Describe your build once there, and a bare tsc does the rest. Start with strict: true and keep source (src) separate from output (dist).
  • Watch mode (tsc --watch) recompiles automatically as you save, tightening the feedback loop.
  • In a modern toolchain, type-checking and code-generation are often split between tsc and a build tool. Knowing that they’re two jobs is what keeps real-world setups from looking like magic.

Get comfortable with this and the rest of your TypeScript journey rests on solid ground. Everything else — fancier configs, frameworks, bigger tooling — is just variations on the same handful of ideas you just learned.

Tags:typescripttsctsconfigcompilertoolchainsetup
728 × 90Ad Space AvailablePlace your ad here

Related Articles

See All Articles

You Might Also Like

Frontend best practices overview cover
Frontend / Fundamentals

Frontend Best Practices: An Overview

A friendly map of what good frontend really means — semantic HTML, clean CSS, unobtrusive JavaScript, responsive layouts, performance, and progressive enhancement, with pointers to go deeper.

Sep 20, 20268 min read
A Frontend Developer Roadmap cover with the path HTML to CSS to JavaScript
Frontend / Fundamentals

A Frontend Developer Roadmap: What to Learn, and in What Order

A calm, step-by-step learning path for beginners: HTML, CSS, JavaScript, developer tools, responsive and accessible design, a framework, TypeScript, and deployment, with the reasoning behind each step.

Sep 20, 202611 min read
Title card reading Styling and Interactivity over a dark blue ACY Partner background
Frontend / Fundamentals

How Styling and Interactivity Work

A beginner-friendly look at how CSS turns plain HTML into a designed layout, and how JavaScript adds behavior — the structure, style, behavior mental model for building web pages.

Sep 20, 20269 min read
Three front-end layers combining on one web page
Frontend / Fundamentals

How HTML, CSS, and JavaScript Work Together

A hands-on walkthrough for beginners: build one small button, give it structure with HTML, looks with CSS, and behavior with JavaScript, and watch the three layers cooperate on a real page.

Sep 20, 20268 min read
The Frontend Developer Toolkit cover with editor, browser, and CLI motifs
Frontend / Fundamentals

The Frontend Developer Toolkit

A friendly tour of the everyday tools a frontend developer relies on — code editor, browser and DevTools, terminal, version control, package managers, and a dev server — and what each one is actually for.

Sep 20, 202610 min read
Cover illustration for What Frontend Developers Do
Frontend / Fundamentals

What Frontend Developers Do: A Beginner's Guide to the Role

A clear, beginner-friendly look at what frontend developers actually do every day: turning designs into working interfaces, building reusable UI, and caring about responsiveness, accessibility, and speed.

Sep 20, 202610 min read