Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Const

strictNullChecks

strictNullChecks controls whether null and undefined are treated as distinct types. When enabled, TypeScript requires code to handle possibly absent values before using them as definite values.

How it works

When enabled, strictNullChecks gives null and undefined separate types instead of treating them as valid values for every type. Code must account for those possibilities before using a value where a concrete type is required, typically through narrowing or an explicit union.

Syntax

{"compilerOptions":{"strictNullChecks":true}}

Key points

  • Enabling the option separates null and undefined from ordinary concrete types.
  • The compiler rejects using a possibly absent value in a context requiring a definite value.
  • The disabled behavior can allow assumptions about presence that fail when the program runs.
  • The setting is enabled by assigning true in the compiler configuration.
  • With the option off, APIs such as find are represented without their possible undefined result.

Common mistakes

  • A possibly null or undefined value cannot be used as a concrete value until the code narrows or otherwise handles it.
  • Disabling the option can hide problems that later become runtime errors.
  • Lookup results such as Array.find may require an existence check before property access.

Example: Check an optional lookup result

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

const users = [{ name: "Ada" }];
const user = users.find(candidate => candidate.name === "Grace");

if (user) {
  console.log(user.name);
}

With strict null checking enabled, find returns a value that may be undefined, so the guard is required before reading name.

When to use it

Safe collection lookups

Prevent property access on missing lookup results.

Boundary validation

Make nullable API responses explicit in types.

Large-codebase safety

Expose absence-related defects during compilation.

Interview questions

QWhat does strictNullChecks change?

With strictNullChecks enabled, null and undefined are distinct types rather than being ignored. A value that may contain either cannot be used where a concrete value is required until the possibility is handled.

Follow-up: How would you represent a nullable number? Use the union type number | null, then narrow it before operations that require number.

QWhy can Array.find require a guard?

Array.find is modeled as returning S | undefined when strict null checking is enabled. Therefore, callers must check the result before accessing its properties or passing it to code that expects S.

Follow-up: What is the practical benefit? The compiler exposes missing-result paths that could otherwise become runtime failures.

QWhat is the risk of leaving strictNullChecks disabled?

With the option disabled, null and undefined are effectively ignored by the type system, so code can use values as though they were always present. Enabling it makes those absence cases visible during compilation.

Follow-up: What should a project do when migrating? Add the checks or explicit unions required by the newly reported errors, rather than suppressing them indiscriminately.

  • strict
  • null
  • undefined
  • Array.find

Source: TSConfig Option: strictNullChecks - TypeScript. Checked 2026-10-15.