strictNullChecks
The compiler option that makes null and undefined separate types, so you must handle them before using a value.
In more detail
Without it, any variable could secretly be null and crash when used. With it, findUser returning string | undefined forces a check before calling toUpperCase. It is part of strict mode.
Related terms
- strict (compiler option) — The strict compiler option, which turns on a family of stronger checks such as strictNullChecks and noImplicitAny in one setting.
- null — A special value meaning no value or no object, set on purpose to show that something is empty or absent.
- undefined — The JavaScript value meaning not set: a variable with no value yet, a missing property or a function that returned nothing.
- type narrowing — The compiler refining a broad type to a more specific one inside a block, after a check proves which case applies.
Taught in
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript