TS TypeScript

TypeScript: Running Code & Tools

Compiling TypeScript

TypeScript code is compiled to JavaScript using tsc (the TypeScript Compiler):

tsc my_file.ts              # produces my_file.js
tsc --watch                  # auto-recompile on every change
npx ts-node my_file.ts       # run TypeScript directly (dev only)

Project configuration -- tsconfig.json

npx tsc --init               # generates a tsconfig.json
tsc                          # compiles ALL .ts files in the project

Key tsconfig options:

Option What it does
target Which JS version to emit (ES2020, ES5, etc.)
module Module system (commonjs, esnext)
strict Enables all strict type-checking options (recommended!)
outDir Output directory for compiled .js files
rootDir Input directory for .ts source files

Editors

  • VS Code -- built-in TypeScript support (no extension needed!). Uses tsc behind the scenes.
  • WebStorm -- JetBrains IDE with full TS support
  • Neovim/Vim with typescript-language-server for LSP support

Installing TypeScript

npm install -g typescript          # global install (gives you `tsc`)
npm install --save-dev typescript  # project-local (recommended)
npx tsc                            # uses local version if available

Quick check below!