BACK TO DIRECTORY
settingintermediate

TypeScript Strict Mode

The most comprehensive TypeScript configuration for maximum type safety. Enables all strict flags plus additional checks like noUncheckedIndexedAccess, exactOptionalPropertyTypes, and noPropertyAccessFromIndexSignature. Includes recommended ESLint rules for TypeScript and explains the rationale behind each setting. Ideal for new projects starting with strict typing from day one.

678 STARS
9.9k DOWNLOADS
claude-templates
typescriptstricttypesconfigsafety

CONFIGURATION

json
1{
2 "compilerOptions": {
3 // Strict type checking
4 "strict": true,
5 "noUncheckedIndexedAccess": true,
6 "exactOptionalPropertyTypes": true,
7 "noPropertyAccessFromIndexSignature": true,
8 "noImplicitReturns": true,
9 "noFallthroughCasesInSwitch": true,
10 "noImplicitOverride": true,
11 "forceConsistentCasingInFileNames": true,
12 "verbatimModuleSyntax": true,
13
14 // Module resolution
15 "target": "ES2022",
16 "module": "ESNext",
17 "moduleResolution": "bundler",
18 "resolveJsonModule": true,
19 "isolatedModules": true,
20 "esModuleInterop": true,
21
22 // Output
23 "noEmit": true,
24 "declaration": true,
25 "declarationMap": true,
26 "sourceMap": true,
27
28 // Paths
29 "baseUrl": ".",
30 "paths": {
31 "@/*": ["./src/*"]
32 },
33
34 // Libraries
35 "lib": ["DOM", "DOM.Iterable", "ES2022"],
36 "jsx": "preserve",
37 "incremental": true,
38
39 // Plugins
40 "plugins": [{ "name": "next" }]
41 },
42 "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
43 "exclude": ["node_modules", "dist", ".next"]
44}
45
46// What each strict flag does:
47// strict: true -> Enables all strict mode flags
48// noUncheckedIndexedAccess -> array[0] is T | undefined
49// exactOptionalPropertyTypes -> { x?: string } is string | undefined, not string | undefined | missing
50// noPropertyAccessFromIndexSignature -> forces obj["key"] over obj.key for index signatures
51// noImplicitReturns -> every code path must return a value
52// noFallthroughCasesInSwitch -> switch cases must break or return
53// noImplicitOverride -> override keyword required for inherited methods
54// verbatimModuleSyntax -> enforces type-only imports with "import type"