You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/2026-04/advanced-tsconfig-settings/index.mdx
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,9 @@ freebie: "ts-util-cheat-sheet"
9
9
10
10
TypeScript's `strict` mode is a great starting point, but it leaves a surprising number of dangerous patterns unchecked. There is a whole category of compiler options that are disabled by default, and enabling them can catch subtle bugs that would otherwise slip through to production. In this article I will walk through the TSConfig settings that I think should be enabled in nearly every project, organized from settings I consider non-negotiable all the way to JS-only migration helpers.
11
11
12
+
_If you prefer to learn visually, check out the video version of this article._
13
+
`youtube: 35cESnxXH6o`
14
+
12
15
## Must Have
13
16
14
17
These settings have essentially no downside and catch real bugs. Enable all of them.
JavaScript has a labeled statement syntax that almost nobody uses intentionally. An unused label is almost always a typo. The classic case is someone who meant to write an object key but accidentally put the key outside the object, creating a label instead:
98
+
95
99
```json
96
100
{
97
101
"compilerOptions": {
@@ -300,7 +304,7 @@ This option is especially valuable if you are using Node.js's native TypeScript
300
304
301
305
Some TypeScript features emit JavaScript code when compiled; they are not just type annotations. These features cannot be used with type-stripping tools because there is no JavaScript to strip them to:
302
306
303
-
```ts
307
+
````ts
304
308
// Error: Enums are not erasable syntax.
305
309
// Enums compile to a JavaScript object, so the stripper has no JS to output.
306
310
enumDirection {
@@ -337,7 +341,7 @@ class User {
337
341
this.age = age
338
342
}
339
343
}
340
-
```
344
+
````
341
345
342
346
The whole purpose of this option to ensure your code will work when your types are stripped out without needing them to be compiled with a tool like `tsc`. If you are using `tsc` to compile your code, this option is not necessary since `tsc` can handle all TypeScript features, but I still enable it since features like enums are generally considered bad practice anyway.
343
347
@@ -391,7 +395,8 @@ class Animal {
391
395
392
396
// Error: There is no method 'speak' to override
393
397
classDogextendsAnimal {
394
-
override speak():string { // TypeScript catches the stale override
398
+
override speak():string {
399
+
// TypeScript catches the stale override
395
400
return"Woof!"
396
401
}
397
402
}
@@ -422,7 +427,7 @@ type User = {
422
427
// Error: Type 'undefined' is not assignable to type 'string'.
0 commit comments