#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
Question 33 of 48easy

What is Strict Mode in TypeScript?

Enabling stricter type checking.

What You'll Learn

  • What strict mode enables
  • Individual strict flags
  • Why use strict mode

Enabling Strict Mode

data.jsonJSON
// tsconfig.json
{
  "compilerOptions": {
    "strict": true
  }
}

What strict Enables

FlagDescription
strictNullChecksnull/undefined are distinct types
strictFunctionTypesStricter function type checking
strictBindCallApplyCheck bind, call, apply
strictPropertyInitializationClass properties must be initialized
noImplicitAnyError on implicit any
noImplicitThisError on implicit this
alwaysStrictEmit "use strict"

Examples

code.tsTypeScript
// strictNullChecks
let name: string = null; // Error!

// noImplicitAny
function fn(x) { }  // Error: x has implicit any

// strictPropertyInitialization
class User {
  name: string; // Error: not initialized

  // Fix:
  name: string = "";
  // or
  name!: string; // Definite assignment
}

Why Use Strict?

  • Catch more errors at compile time
  • Better IDE support
  • Safer refactoring
  • Recommended for new projects