Your screen is too narrow. Try landscape orientation?

What does strict do in a TypeScript config?

2 min read

Enabling this strict flag in TypeScript's config file allows for more reliable program correctness. In addition, it enables a few other flags, which results in more substantial type restrictions and accuracy. Therefore, enabling this flag is recommended for all new projects. However, if you want to do it in an existing project, you can enable this flag and disable the related flags while gradually updating your project to adopt the strict mode.

The strict flag alone enables the following flags:

  • alwaysStrict - enforces ES strict mode and adds "use strict" to each source file
  • strictNullChecks - separates null and undefined types, resulting in type errors if used where a value is expected
  • strictBindCallApply - ensures that bind(), call(), and apply() are invoked with correct arguments
  • strictFunctionTypes - ensures that function parameters are checked for compatibility when assigning functions
  • strictPropertyInitialization - raise an error if property is declared but not initialized
  • noImplicitAny - raise an error if inferrence fails, since resulting type will be any
  • noImplicitThis - raise an error on this expressions with an implied any type
  • useUnknownInCatchVariables - catch clause variables will be typed as unknown

All these flags are false by default, but once you enable the strict flag, the behavior of the flags mentioned above is automatically enabled, which could result in more errors in your existing codebase.

typescriptconfigstrict flag