#typescript
#config
Day 27: Configuration Deep Dive (tsconfig.json)
Controlling the Beast
Welcome to Day 27! tsconfig.json controls how TypeScript works.
Key Options
target
Which JS version to output? ES5, ES6, ESNext.
If you target ES5, async/await is compiled to a state machine. If ESNext, itβs left as is.
module
How to handle modules? CommonJS (Node), ESNext (Modern), NodeNext.
strict
ALWAYS SET THIS TO TRUE. It enables:
noImplicitAny: Noanywithout permission.strictNullChecks: Handlenullexplicitly.- And more.
Paths and BaseUrl
Clean up your imports.
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@components/*": ["components/*"]
}
}
Now: import Button from "@components/Button" instead of ../../components/Button.
Include / Exclude
Tell TS which files to compile.
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
Challenge for Today
- Open your
tsconfig.json. - Look for
strict. Is it true? - Change
targettoES5and check a generated JS file. - Change it back.
See you on Day 28 for Linting and Formatting!