What is strict null checks and why is it important?
Why Interviewers Ask This
This tests whether you can apply TypeScript knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Strict null checks ("strictNullChecks": true) is one of the most impactful TypeScript settings. Without it (the default in older TypeScript versions), null and undefined are silently assignable to every type — you could assign null to a string variable and TypeScript would not complain. This mirrors JavaScript's behavior but defeats the purpose of type safety. With strict null checks enabled, null and undefined become their own types and are NOT automatically assignable to other types. To allow null: let name: string | null = null — you must explicitly include it in the union. This forces you to handle null cases, which eliminates the notorious "Cannot read properties of null" runtime errors. It also unlocks TypeScript's control flow narrowing for null checks — after if (user !== null), TypeScript knows user is not null. Always enable strict null checks — the slight increase in boilerplate is a worthwhile trade-off for dramatically safer code.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a TypeScript codebase.
Previous
What is the this type in TypeScript?
Next
What is the useUnknownInCatchVariables option in TypeScript?