Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us
Taking new clients

Need a dev team that ships?

011BQ builds TypeScript-first products, migrations, and internal tools for startups and scale-ups.

  • JS/TS migration & codebase modernisation
  • Custom dev tools & internal platforms
  • React, Next.js & Node.js engineering
  • Code review, architecture & tech advisory

Or reach us directly

011bq.com

Send us a message

We respond within 1 business day.

check_dark

Thank You!

Your message has been successfully sent. We will get back to you soon!

Message sent!

Thanks for reaching out. The 011BQ team will get back to you within 1 business day.

HomeChevronBlogChevronTypeScript Strict Mode: A Complete Guide to Enabling and Fixing All Errors

TypeScript Strict Mode: A Complete Guide to Enabling and Fixing All Errors

j
js2ts Team
22/05/2026·1 minute 59 seconds read
TypeScript Strict Mode: A Complete Guide to Enabling and Fixing All ErrorsTypeScript Strict Mode: A Complete Guide to Enabling and Fixing All Errors

What Is TypeScript Strict Mode?

TypeScript's strict flag is a shorthand that enables a group of type-checking options that together catch a much wider class of bugs. When you turn on "strict": true in your tsconfig.json, TypeScript enables:

  • strictNullChecks — null and undefined are not assignable to other types
  • noImplicitAny — variables without a type annotation can't have implicit any
  • strictFunctionTypes — function parameter types are checked contravariantly
  • strictBindCallApply — bind/call/apply are type-checked against their target function
  • strictPropertyInitialization — class properties must be initialized in the constructor
  • noImplicitThisthis expressions without an explicit type raise an error
  • useUnknownInCatchVariables — caught errors in catch blocks are typed as unknown

Why You Should Enable Strict Mode

Strict mode is where TypeScript's real value lives. Without it, you can write TypeScript that doesn't actually prevent the most common runtime errors. With strict mode, TypeScript catches null pointer dereferences, implicit any types that bypass type checking, and incorrect function signatures — before your code runs.

The TypeScript team recommends starting every new project with strict mode. For existing projects, the incremental approach below makes it manageable.

How to Enable Strict Mode Incrementally

For an existing codebase, enabling all strict options at once will produce hundreds of errors. Instead, enable them one at a time in order of impact:

// tsconfig.json
{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Fix all errors from strictNullChecks first, then add noImplicitAny, then the rest. This keeps the error count manageable.

Fixing strictNullChecks Errors

The most common strict mode errors come from strictNullChecks. The pattern is: Object is possibly null or undefined.

Pattern 1: Add a null check

// Before
const name = user.name.toUpperCase(); // error if user.name is null

// After
const name = user.name?.toUpperCase() ?? "";

Pattern 2: Use a type assertion when you know the value is non-null

const element = document.getElementById("app")!; // non-null assertion

Pattern 3: Narrow the type with a guard

if (user.name !== null) {
  const name = user.name.toUpperCase(); // TypeScript knows it's non-null here
}

Fixing noImplicitAny Errors

The error Parameter 'x' implicitly has an 'any' type appears when TypeScript can't infer a type. Fix it by adding explicit annotations:

// Before
function process(data) { ... }

// After
function process(data: UserData): ProcessedResult { ... }

Fixing strictPropertyInitialization Errors

Class properties must be initialized. Three options:

class Service {
  // Option 1: initialize inline
  private cache: Map<string, string> = new Map();

  // Option 2: initialize in constructor
  private db: Database;
  constructor(db: Database) {
    this.db = db;
  }

  // Option 3: declare as possibly undefined
  private config?: Config;
}

Conclusion

TypeScript strict mode is non-negotiable for production-quality code. Enable it incrementally, starting with strictNullChecks, and work through each category of errors. The bugs you catch during this process are bugs that would have reached production otherwise. For a full reference of TypeScript error codes, see our TypeScript Errors guide.

Share