📎 Webclip
TypeScript Advanced Types — Nullable Types and Type Aliases
TypeScript supports nullable types so properties can accept undefined when strictNullChecks is enabled. Without the nullable operator, members cannot be assigned null or undefined under that flag.
Reading notes#
- With strictNullChecks on, TypeScript rejects null or undefined on type members that do not use the nullable operator.
- A question mark after a member name marks it as nullable.
- The example interface Person sets age to null and produces a type error because age is declared as number.
- The article says TypeScript also has other advanced types, including intersection types, union types, type guards, nullable types, and type aliases.
- This piece focuses on nullable types and type aliases.
