Introduction to Strict Compiler Options
Learn the significance of strict compiler options and other TypeScript settings to prevent programming errors.
Introduction to TypeScript compiler options
The TypeScript compiler uses the tsconfig.json
file to specify a number of compilation options. These options include:
-
What version of JavaScript we would like to generate for.
-
What the output directory should be.
-
Whether or not to allow JavaScript source files within the project directory.
Significance of the strict
compiler option
One of the most important options is simply named strict
, and this single option turns on a group of other compiler options.
The purpose of the strict
compiler
options is to apply a number of checks to our code and determine whether any of
these checks fail.
As an example, these strict
options can determine if a variable could be undefined
at the time of use or if the variable itself is never used. If we set the value of the strict
option to false
or turn it off, then each of these options needs to be turned on individually. We will explore these other strict options in detail.
The strict
option is the default that is used when creating a new TypeScript project, and we should strive to keep this option turned on. Relaxing the strict compiler options used by the TypeScript compiler should always be done very carefully and should be a deliberate act. There are, however, occasions when we should allow for
the strict options to be relaxed.
Get hands-on with 1200+ tech skills courses.