Object Types with Mixed Value Types
What you'll learn: How to define object types where each property can have a completely different type — primitives, arrays, or even nested objects.
The Core Idea
Up until now, you've seen object types with single properties or multiple properties of the same kind. In real-world TypeScript, objects often contain a mix of different value types. One property might be a string, another a number, a third an array, and yet another a nested object. TypeScript handles this naturally — you simply declare each property with its own type.
Mixing Value Types Freely
Here's an object type that combines primitives, arrays, and nested objects:
let user: {
name: string;
age: number;
isActive: boolean;
tags: string[];
address: {
city: string;
zip: number;
};
};
user = {
name: "Alice",
age: 30,
isActive: true,
tags: ["developer", "typescript"],
address: {
city: "Portland",
zip: 97201
}
};
Each property has its own independent type. name is a string, tags is a string[], and address is itself an object type with city and zip properties.
Why This Matters
Real data structures rarely contain uniform types. An API response might have a status code (number), a message (string), data (array), and metadata (nested object). TypeScript's object types mirror this reality by letting you specify exactly what shape your data takes, no matter how heterogeneous.
Key Takeaway: Object types in TypeScript can freely mix primitives, arrays, and nested objects as property values — each property gets its own independent type, creating precise contracts for complex data structures.