Setup & tsconfig Basics
10 min read
Setup & tsconfig Basics
TypeScript is installed as a development dependency. The compiler (tsc) reads a tsconfig.json file at the root of your project to understand how to compile your code.
ts
// Install TypeScript
// npm install --save-dev typescript
// npx tsc --init (generates tsconfig.json)A tsconfig.json controls the compiler. The most important options live under compilerOptions. Here is a sensible baseline for modern projects.
ts
// tsconfig.json (JSON, not TypeScript — shown here for illustration)
// {
// "compilerOptions": {
// "target": "ES2022",
// "module": "NodeNext",
// "moduleResolution": "NodeNext",
// "strict": true,
// "outDir": "dist",
// "rootDir": "src",
// "esModuleInterop": true,
// "skipLibCheck": true
// },
// "include": ["src"]
// }Always enable "strict": true. It activates a set of compiler checks (including strictNullChecks and noImplicitAny) that catch the most common category of TypeScript bugs. Projects at CPCODELAB enforce strict mode from day one.
Key compiler options explained
target— the JavaScript version emitted (e.g.ES2022)module— the module system used in output (e.g.NodeNext,ESNext,CommonJS)strict— enables the full suite of strict type checksoutDir— where compiled JavaScript files are writtenrootDir— the root of your TypeScript source filesesModuleInterop— allows default imports from CommonJS modules
Ready to test yourself?
Practice TypeScript— quiz & coding exercises