Describing shapes.
WHAT AN INTERFACE DESCRIBES
The shape of an object: what properties it has, and of what type.
WHY THAT MATTERS
It documents what code expects, and the compiler enforces it.
WHAT TYPE ALIASES PROVIDE
A name for any type, including unions and combinations.
WHAT TO USE FOR OBJECT SHAPES
Either, consistently.
WHAT OPTIONAL PROPERTIES INDICATE
That a property may be absent.
WHAT THAT FORCES
Checking before use.
WHAT READONLY PROPERTIES INDICATE
That a value should not be changed after creation.
WHAT GENERICS PROVIDE
Types parameterised by another type, so a structure works with any content while remaining checked.
WHY THAT MATTERS
It avoids either duplicating code per type, or abandoning checking.
WHAT TO DEFINE FOR EXTERNAL DATA
The shape you expect.
WHAT TO STILL DO
Validate at runtime.
WHY
A declared type is an assertion, not a guarantee.
WHAT TO ORGANISE
Shared types in one place, so they are reused rather than redeclared.