Unit 1 · Module 4

The Object — A Different Kind of Type

A container type that holds multiple values together

The five basic types are values — a single piece of data. "Ruthnie" is just a name. 42 is just a number.

An object is a container type. It holds multiple values together because they all describe the same thing:

An object holding multiple types

const pet = {
  name: "Biscuit",
  species: "dog",
  age: 3,
  isVaccinated: true
}

pet is one object. But inside it you've got a string, a string, a number, and a boolean — all living together because they're all describing the same thing.

When TypeScript looks at an object, it doesn't just ask "what type is this?" It asks "what is the shape of this?" — meaning, what properties does it have, and what type is each one?

Analogy: Ingredients and recipes

The basic types are the ingredients. An object is the recipe that combines them.

An object without anything inside it is technically valid — but useless. Like a filing cabinet with no folders. It only has meaning because of what's inside it.