Setting Up TypeScript
Before writing real TypeScript you need two things: the compiler, and somewhere to run its output. This lesson installs TypeScript into a project, compiles a first file by hand, and shows the faster ways developers usually run .ts files day to day.
Option 1: no install at all
If you just want to experiment, the official TypeScript Playground at typescriptlang.org/play runs entirely in the browser. It shows type errors as you type, the compiled JavaScript side by side, and lets you switch compiler versions and settings. Every lesson on this site also has an in-page editor for running examples.
Option 2: install it in a project
For real work, TypeScript is installed per project as a development dependency, so everyone on the team uses the same version. You'll need Node.js installed first; check with node -v.
mkdir hello-ts cd hello-ts npm init -y npm install --save-dev typescript npx tsc --version
Version 7.0.2
--save-dev records TypeScript under devDependencies in package.json, because it's only needed while building, not when the finished JavaScript runs. npx tsc runs the copy installed inside this project rather than any global one.
Since version 7.0 (July 2026), the typescript package contains a native compiler written in Go, which typically builds projects around ten times faster than the older JavaScript-based compiler. The language itself is unchanged, so everything in this course applies whichever version you have.
npm install -g typescript works, but a global compiler can drift out of step with what a project expects. Projects pin their own version so that "it compiles on my machine" means the same thing for everyone.Compile your first file
Create index.ts:
const items: string[] = ["keyboard", "mouse", "monitor"]; for (const item of items) { console.log(`Packing ${item}`); }
Then compile it and run the JavaScript that comes out:
npx tsc index.ts node index.js
Packing keyboard Packing mouse Packing monitor
Running tsc with a file name compiles just that file using default settings and writes index.js next to it. Real projects instead use a tsconfig.json file, created with npx tsc --init, so tsc knows which files to compile and how strict to be — lesson 38 covers it in depth.
tsconfig.json exists, current TypeScript versions refuse to compile a single named file (tsc index.ts) and report error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline. Run plain npx tsc to build the project, or add --ignoreConfig if you really want to compile one file with default settings.Watch mode
Re-running tsc after every change gets tedious. Watch mode keeps the compiler running and rebuilds whenever a file is saved:
npx tsc --watch
It prints any new errors as soon as you save, which makes it a handy companion in a second terminal window.
Running .ts files directly
During development, many people skip the separate compile step. These tools are common:
| Tool | What it does | Type-checks? |
|---|---|---|
tsx (npm package) | npx tsx index.ts — strips types on the fly and runs the file in Node | No |
| Node.js 22.18+ / 23.6+ | node index.ts — Node can strip erasable type syntax itself | No |
| Deno, Bun | Alternative runtimes that run .ts files natively | Deno can; Bun doesn't |
tsc --noEmit | Checks the whole project and writes no files | Yes — this is the checker |
Notice that the "run it directly" tools generally don't report type errors — they only remove the types. A typical setup is to run code with one of them for speed and run tsc --noEmit (in the editor, a pre-commit hook or CI) to catch type errors.
Editor support
VS Code ships with TypeScript support built in: errors are underlined as you type, hovering a variable shows its type, and F12 jumps to a definition. Other editors (WebStorm, Neovim, Zed, Sublime) use the same TypeScript language service through plugins, so the experience is similar everywhere.