Strict mode is actually a combination of six other flags (as of TypeScript 3.8):
noImplicitAny
strictNullChecks
(since 2.0)noImplicitThis
(since 2.0)strictFunctionTypes
(since 2.6)strictPropertyInitialization
(since 2.7)strictBindCallApply
(since 3.2)Each option can be enabled or disabled separately. Some of them make TypeScript’s type checking better and some help make your code more readable and less error-prone.
You can enable strict mode in your tsconfig.json
:
{
"compilerOptions": {
"strict": true,
}
}
You can disable any option that you don’t like from the strict family in the compileOptions
as well (e.g. "noImplicitAny": false
).
I think the most important flags are noImplicitAny
and strictNullChecks
. These two will really improve the type checking and readability of your code.
Let’s take a look at each flag.
#nodejs #javascript #typescript