Compiling TS and tsconfig.json
Run tsc to compile TypeScript, configure the compiler with tsconfig.json options like strict, target, and outDir.
Installing the TypeScript Compiler
Install TypeScript as a dev dependency. The tsc CLI compiles TypeScript files. With Vite or Next.js, the bundler handles compilation — but tsc is still used for type checking.
npm install --save-dev typescript
npx tsc --version # verify installation
npx tsc app.ts # compile a single fileInitialising tsconfig.json
Run npx tsc --init to generate a tsconfig.json with all options commented out and sensible defaults. This file is the single configuration for the TypeScript compiler.
npx tsc --init
# Creates tsconfig.json with ~100 commented-out optionsAll lessons in this course
- Why TypeScript: Types Catch Bugs at Compile Time
- Primitive Types Unions and Type Aliases
- Interfaces and Object Types
- Compiling TS and tsconfig.json