06 / 08

How does TypeScript handle strict null checks?

Strict null checks (strictNullChecks) is a TypeScript compiler option that makes null and undefined their own distinct types — preventing them from being assigned to other types unless explicitly allowed.

Without strictNullChecks (Default OFF — Dangerous)
With strictNullChecks (ON — Safe)
Enabling strictNullChecks
Difficulty: 6/10
Topics: strict null checks, type narrowing, non-null assertion

Scenario Questions

0-2 years experience
  1. 1

    You have a function that returns a string or null. How would you call it and safely use the result with strictNullChecks enabled?

  2. 2

    If you assign undefined to a variable typed as number, what compile error do you see with strictNullChecks on, and how can you fix it?

  3. 3

    What does the ! non‑null assertion operator do, and when would you use it in a small component?

2-5 years experience
  1. 1

    We recently enabled strictNullChecks in our project and a component started throwing type errors around optional props. Walk me through how you'd resolve those errors.

  2. 2

    During a refactor, a utility function that previously returned any now returns string | null. Explain why a call site might break and how you'd adjust the code.

  3. 3

    You notice a runtime crash because a value was null despite TypeScript not complaining. What could cause that under strictNullChecks, and how would you debug it?

5-8 years experience
  1. 1

    Our large codebase mixes JavaScript and TypeScript files, and we want to enable strictNullChecks across the repo. What strategy would you use to roll it out without breaking many modules?

  2. 2

    Design a pattern for handling API responses that may have missing fields while keeping strict null checks on, and discuss trade‑offs of using type guards versus a utility library.

  3. 3

    Explain any performance implications of enabling strictNullChecks in a high‑throughput Node service, and how you'd monitor for issues after the change.

8+ years experience
  1. 1

    As a staff engineer, you need to lead a migration of a legacy monorepo to strict null checks, affecting multiple teams. How would you structure the migration plan, tooling, and communication to minimize risk?

  2. 2

    Discuss the long‑term maintenance impact of strict null checks on cross‑team shared libraries, especially regarding versioning and backward compatibility.

  3. 3

    If a critical third‑party library lacks proper nullability typings, how would you integrate it while keeping strictNullChecks enabled across the organization?

Follow-up Questions

  • Can you give an example where using the non‑null assertion could hide a bug?
  • How does strictNullChecks affect third‑party type definitions that may be incomplete?
  • When might you consider disabling strictNullChecks for a specific file, and what are the risks?