Strict Options
In this section of the chapter, we will explore the strict set of compiler options, all of which come into play when we turn the main "strict"
option from true to false. Note that if we turn the main "strict"
option to false, then we must set the desired "strict"
option to true in order for it to become active.
strictNullChecks
The strictNullChecks
compiler option is used to find instances in our code where the value of a variable could be null or undefined at the time of usage. This means that when the variable is actually used, if it has not been properly initialized, the compiler will generate an error message. Consider the following code:
let a: number;
let b = a;
Here, we have defined a variable named a
that is of type number. We then define a variable named b
and assign the value of a
to it. This code will generate the following error:
error TS2454: Variable 'a' is used before being assigned
This...