New —strict master option

New checks added to TypeScript are often off by default to avoid breaking existing projects. While avoiding breakage is a good thing, this strategy has the drawback of making it increasingly complex to choose the highest level of type safety, and doing so requires explicit opt-in action on every TypeScript release. With the —strict option it becomes possible to choose maximum type safety with the understanding that additional errors might be reported by newer versions of the compiler as improved type checking features are added.

The new —strict compiler option represents the recommended setting of a number of type checking options. Specifically, specifying —strict corresponds to specifying all of the following options (and may in the future include more options):

  • —strictNullChecks
  • —noImplicitAny
  • —noImplicitThis
  • —alwaysStrictIn exact terms, the —strict option sets the default value for the compiler options listed above. This means it is still possible to individually control the options. For example,
  1. --strict --noImplicitThis false

has the effect of turning on all strict options except the —noImplicitThis option. Using this scheme it is possible to express configurations consisting of all strict options except some explicitly listed options. In other words, it is now possible to default to the highest level of type safety but opt out of certain checks.

Starting with TypeScript 2.3, the default tsconfig.json generated by tsc —init includes a "strict": true setting in the "compilerOptions" section. Thus, new projects started with tsc —init will by default have the highest level of type safety enabled.