After this lesson, you will be able to: Configure tsconfig.json with strict mode + path aliases; understand each strict flag.
tsconfig.json controls everything. Get strict mode on; understand the trade-offs.
Use as a template for new projects.
{"compilerOptions": {"target": "ES2022","module": "NodeNext","moduleResolution": "NodeNext","lib": ["ES2022"],"strict": true,"noUncheckedIndexedAccess": true,"esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true,"resolveJsonModule": true,"isolatedModules": true,"verbatimModuleSyntax": true,"outDir": "./dist","rootDir": "./src","baseUrl": ".","paths": {"@/*": ["src/*"]}},"include": ["src/**/*"],"exclude": ["node_modules", "dist"]}
`strict: true` enables: noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, useUnknownInCatchVariables. Most important: strictNullChecks, every value can be null or undefined unless typed otherwise. Catches 95% of real bugs.
`"@/*": ["src/*"]` lets you write `import x from '@/lib/util'` instead of `../../../lib/util`. Bundlers (Vite, Next.js) usually respect tsconfig paths automatically. For node-runtime code, also set up tsconfig-paths or use a bundler. Default for new projects: `@/` for src.
Disabling strict to make code compile. Defeats the point. Setting `noImplicitAny: false`. Lets type errors hide. Forgetting `noUncheckedIndexedAccess`. `array[i]` is typed as T, not T | undefined, misleading. Skipping `verbatimModuleSyntax`. Subtle import/export issues with newer bundlers.
Pick the senior answer.
Sign in and purchase access to unlock this lesson.