What is strict null checks and why is it important?
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.
Previous
What is the this type in TypeScript?
Next
What is the useUnknownInCatchVariables option in TypeScript?