TS BASICSChapter 1 · TS Basics
Object Types and Optional Properties
You can describe an object's shape right where you use it: star: { name: string; mag?: number }. A ? makes a property optional: it may be missing, so its type includes undefined, and TypeScript makes you check before using it. Object literals are checked exactly: a missing required property and a misspelled extra one are both errors.
Worked example
How it reads
mag?: numbermeans the property can be left out- Checking
=== undefinednarrowsmagto a plain number afterwards - When the shape is used in many places, give it a name with an interface

Cloud tip:
value ?? fallback supplies a default only when the value is null or undefined.

