Course contentsShow
← TypeScript
Lesson 290 of 1,7967. ObjectsFree lesson

Multiple Properties in One Type

Combining multiple property declarations in a single object type with semicolons or commas.

Multiple Properties in One Type

What you'll learn: How to define object types with more than one property using semicolons or commas as separators.

The Core Idea

In the last lesson, you saw how to declare a single property in an object type literal. Real-world objects almost always have multiple properties, and TypeScript lets you combine them in one type definition. You can separate properties with either semicolons (;) or commas (,)—both work identically.

Syntax Options

Here's an object type with three properties using semicolons:

let person: { name: string; age: number; active: boolean };

person = {
  name: "Alice",
  age: 30,
  active: true
};

And here's the exact same type using commas:

let person: { name: string, age: number, active: boolean };

person = {
  name: "Alice",
  age: 30,
  active: true
};

Both are valid TypeScript. The choice between semicolons and commas is purely stylistic—pick one and stay consistent in your codebase.

Think of It Like a Blueprint

Imagine you're filling out a form with multiple fields: name, age, and whether you're an active member. The object type is like the template for that form, listing every field and what type of information belongs in each slot. TypeScript checks that you fill in all the fields with the right types.

Practical Example

let product: { id: number; title: string; inStock: boolean };

product = {
  id: 101,
  title: "Laptop",
  inStock: true
}; // ✓ All properties match

product = {
  id: 102,
  title: "Mouse"
}; // ✗ Error: missing 'inStock'

Key Takeaway: Object types can declare multiple properties separated by semicolons or commas, creating a complete structure that TypeScript enforces at compile time.