0
# General Configurations
1
2
Standard TypeScript configurations for common development patterns and strictness levels. These configurations provide foundational settings that can be used across different environments.
3
4
## Capabilities
5
6
### Recommended Configuration
7
8
The community-recommended baseline TypeScript configuration that provides a balanced set of compiler options suitable for most projects.
9
10
```typescript { .api }
11
interface RecommendedConfiguration {
12
/** Configuration type */
13
type: "Community Recommended";
14
15
/** Package name */
16
package: "@tsconfig/recommended";
17
18
/** Configuration */
19
config: {
20
$schema: "https://json.schemastore.org/tsconfig";
21
display: "Recommended";
22
compilerOptions: {
23
target: "es2016";
24
module: "commonjs";
25
esModuleInterop: true;
26
forceConsistentCasingInFileNames: true;
27
strict: true;
28
skipLibCheck: true;
29
};
30
};
31
}
32
```
33
34
**Installation:**
35
```bash
36
npm install --save-dev @tsconfig/recommended
37
```
38
39
**Usage:**
40
```json
41
{
42
"extends": "@tsconfig/recommended/tsconfig.json"
43
}
44
```
45
46
**Key Features:**
47
- **ES2016 Target**: Modern JavaScript features with broad compatibility
48
- **CommonJS Modules**: Standard Node.js module system
49
- **Strict Mode**: Enabled for type safety
50
- **ES Module Interop**: Seamless integration with ES modules
51
- **Skip Lib Check**: Faster compilation by skipping declaration file checks
52
53
### Strictest Configuration
54
55
Maximum strictness TypeScript configuration that enables all possible type checking and code quality options.
56
57
```typescript { .api }
58
interface StrictestConfiguration {
59
/** Configuration type */
60
type: "Maximum Strictness";
61
62
/** Package name */
63
package: "@tsconfig/strictest";
64
65
/** Configuration */
66
config: {
67
$schema: "https://json.schemastore.org/tsconfig";
68
display: "Strictest";
69
_version: "2.0.0";
70
compilerOptions: {
71
strict: true;
72
allowUnusedLabels: false;
73
allowUnreachableCode: false;
74
exactOptionalPropertyTypes: true;
75
noFallthroughCasesInSwitch: true;
76
noImplicitOverride: true;
77
noImplicitReturns: true;
78
noPropertyAccessFromIndexSignature: true;
79
noUncheckedIndexedAccess: true;
80
noUnusedLocals: true;
81
noUnusedParameters: true;
82
isolatedModules: true;
83
checkJs: true;
84
esModuleInterop: true;
85
skipLibCheck: true;
86
};
87
};
88
}
89
```
90
91
**Installation:**
92
```bash
93
npm install --save-dev @tsconfig/strictest
94
```
95
96
**Usage:**
97
```json
98
{
99
"extends": "@tsconfig/strictest/tsconfig.json"
100
}
101
```
102
103
**Key Features:**
104
- **Maximum Type Safety**: All strict checking options enabled
105
- **Code Quality Enforcement**: Prevents unused variables and unreachable code
106
- **Exact Optional Properties**: Strict handling of optional properties
107
- **Implicit Return Checking**: Ensures all code paths return values
108
- **Index Signature Safety**: Prevents unsafe property access
109
- **JavaScript Checking**: Type checking for JavaScript files
110
111
## Configuration Comparison
112
113
Understanding the differences between recommended and strictest configurations:
114
115
```typescript { .api }
116
interface ConfigurationComparison {
117
/** Recommended vs Strictest */
118
comparison: {
119
recommended: {
120
purpose: "Balanced development experience";
121
strictness: "moderate";
122
features: [
123
"Basic strict mode",
124
"ES module interop",
125
"Consistent casing",
126
"Skip lib check"
127
];
128
suitableFor: [
129
"New projects",
130
"Learning TypeScript",
131
"Quick prototyping",
132
"Legacy code migration"
133
];
134
};
135
136
strictest: {
137
purpose: "Maximum code quality and safety";
138
strictness: "maximum";
139
features: [
140
"All strict options",
141
"Unused code detection",
142
"Unreachable code prevention",
143
"Exact optional properties",
144
"Index signature safety",
145
"JavaScript type checking"
146
];
147
suitableFor: [
148
"Production applications",
149
"Team development",
150
"Long-term maintenance",
151
"Critical systems"
152
];
153
};
154
};
155
}
156
```
157
158
## Strictness Levels
159
160
Different levels of TypeScript strictness and their implications:
161
162
```typescript { .api }
163
interface StrictnessLevels {
164
/** Basic strictness (recommended) */
165
basic: {
166
options: ["strict"];
167
impact: "Enables fundamental type checking";
168
benefits: ["Type safety", "Better IntelliSense", "Runtime error prevention"];
169
drawbacks: ["Some learning curve", "Potential legacy code issues"];
170
};
171
172
/** Enhanced strictness */
173
enhanced: {
174
options: [
175
"strict",
176
"noImplicitReturns",
177
"noFallthroughCasesInSwitch",
178
"noUnusedLocals",
179
"noUnusedParameters"
180
];
181
impact: "Adds code quality enforcement";
182
benefits: ["Cleaner code", "Better maintainability", "Fewer bugs"];
183
drawbacks: ["More compiler errors", "Stricter refactoring requirements"];
184
};
185
186
/** Maximum strictness */
187
maximum: {
188
options: [
189
"strict",
190
"allowUnusedLabels: false",
191
"allowUnreachableCode: false",
192
"exactOptionalPropertyTypes",
193
"noFallthroughCasesInSwitch",
194
"noImplicitOverride",
195
"noImplicitReturns",
196
"noPropertyAccessFromIndexSignature",
197
"noUncheckedIndexedAccess",
198
"noUnusedLocals",
199
"noUnusedParameters",
200
"isolatedModules",
201
"checkJs"
202
];
203
impact: "Maximum type safety and code quality";
204
benefits: ["Highest code quality", "Maximum type safety", "Comprehensive error detection"];
205
drawbacks: ["Steep learning curve", "Potential development overhead", "Legacy code challenges"];
206
};
207
}
208
```
209
210
## Usage Patterns
211
212
### Starting a New Project
213
214
For new projects, begin with recommended configuration:
215
216
```json
217
{
218
"extends": "@tsconfig/recommended/tsconfig.json",
219
"compilerOptions": {
220
"outDir": "./dist",
221
"rootDir": "./src",
222
"declaration": true,
223
"sourceMap": true
224
},
225
"include": ["src/**/*"],
226
"exclude": ["node_modules", "dist", "**/*.test.ts"]
227
}
228
```
229
230
### Production Applications
231
232
For production code requiring maximum quality:
233
234
```json
235
{
236
"extends": "@tsconfig/strictest/tsconfig.json",
237
"compilerOptions": {
238
"outDir": "./build",
239
"rootDir": "./src",
240
"declaration": true,
241
"declarationMap": true,
242
"sourceMap": true
243
},
244
"include": ["src/**/*"],
245
"exclude": ["node_modules", "build", "**/*.spec.ts"]
246
}
247
```
248
249
### Progressive Adoption
250
251
Gradually increasing strictness over time:
252
253
```json
254
{
255
"extends": "@tsconfig/recommended/tsconfig.json",
256
"compilerOptions": {
257
"noImplicitReturns": true,
258
"noFallthroughCasesInSwitch": true,
259
"noUnusedLocals": true,
260
"noUnusedParameters": true
261
}
262
}
263
```
264
265
### Combined Configurations
266
267
Using multiple configurations together (TypeScript 5.0+):
268
269
```json
270
{
271
"extends": [
272
"@tsconfig/node20/tsconfig.json",
273
"@tsconfig/strictest/tsconfig.json"
274
],
275
"compilerOptions": {
276
"outDir": "./dist"
277
}
278
}
279
```
280
281
### Team Development
282
283
Configuration for team development with consistent standards:
284
285
```json
286
{
287
"extends": "@tsconfig/strictest/tsconfig.json",
288
"compilerOptions": {
289
"baseUrl": ".",
290
"paths": {
291
"@/*": ["src/*"],
292
"@types/*": ["types/*"]
293
},
294
"plugins": [
295
{
296
"name": "typescript-plugin-styled-components"
297
}
298
]
299
},
300
"include": ["src/**/*", "types/**/*"],
301
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
302
}
303
```
304
305
### Migration Strategy
306
307
Migrating from JavaScript to TypeScript:
308
309
```json
310
{
311
"extends": "@tsconfig/recommended/tsconfig.json",
312
"compilerOptions": {
313
"allowJs": true,
314
"checkJs": false,
315
"noImplicitAny": false,
316
"strictNullChecks": false
317
},
318
"include": ["src/**/*"],
319
"exclude": ["node_modules"]
320
}
321
```
322
323
Then gradually enable stricter options:
324
325
```json
326
{
327
"extends": "@tsconfig/recommended/tsconfig.json",
328
"compilerOptions": {
329
"allowJs": true,
330
"checkJs": true,
331
"noImplicitAny": true,
332
"strictNullChecks": true
333
}
334
}
335
```
336
337
Finally, move to strictest:
338
339
```json
340
{
341
"extends": "@tsconfig/strictest/tsconfig.json",
342
"compilerOptions": {
343
"allowJs": false
344
}
345
}
346
```
347
348
## Compiler Option Details
349
350
Detailed explanation of key compiler options in general configurations:
351
352
```typescript { .api }
353
interface CompilerOptionDetails {
354
/** Core strictness options */
355
coreOptions: {
356
strict: "Enables all strict type checking options";
357
noImplicitAny: "Error on expressions with implied 'any' type";
358
strictNullChecks: "Enable strict null checks";
359
strictFunctionTypes: "Enable strict checking of function types";
360
strictBindCallApply: "Enable strict checking of bind/call/apply";
361
strictPropertyInitialization: "Enable strict checking of property initialization";
362
noImplicitReturns: "Error when not all code paths return a value";
363
noImplicitThis: "Error on 'this' expressions with implied 'any' type";
364
};
365
366
/** Quality enforcement options */
367
qualityOptions: {
368
noUnusedLocals: "Error on unused local variables";
369
noUnusedParameters: "Error on unused parameters";
370
noFallthroughCasesInSwitch: "Error on fallthrough cases in switch";
371
allowUnusedLabels: "Allow unused labels";
372
allowUnreachableCode: "Allow unreachable code";
373
exactOptionalPropertyTypes: "Differentiate between undefined and missing properties";
374
noPropertyAccessFromIndexSignature: "Require bracket notation for index signature access";
375
noUncheckedIndexedAccess: "Include undefined in index signature results";
376
};
377
378
/** Module system options */
379
moduleOptions: {
380
esModuleInterop: "Enable interoperability between CommonJS and ES modules";
381
allowSyntheticDefaultImports: "Allow default imports from modules with no default export";
382
forceConsistentCasingInFileNames: "Ensure consistent casing in file names";
383
skipLibCheck: "Skip type checking of declaration files";
384
isolatedModules: "Ensure each file can be safely transpiled in isolation";
385
};
386
}
387
```