Object Types
An object is a bag of named values.
Each name is a key. Each value sits under that key.
TypeScript can describe the whole bag with an object type.
That type is like a checklist of required name tags.
Writing an object type
List each property and its type inside curly braces.
A property is one labeled slot.
Missing a required property is an error.
Optional properties
Put a ? after a property name.
Optional means that slot may be missing.
Inside your code, treat it as maybe undefined.
Undefined means nobody put a value there.
Readonly properties
Readonly means you can set it once.
Then you cannot give that slot a new value.
Like a sticker that stays stuck.
Index signatures
Sometimes you do not know every key ahead of time.
An index signature says any string key maps to one value type.
Map means each key points to a value.
Nested objects
Objects can sit inside objects.
Type each layer so the whole tree is clear.
A tree here means nested bags inside bags.
Object types are checklists for bags of named values. Fill every required blank.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.