TypeScript Cheat Sheet/Combine shapes with intersection

Merge multiple types into one.

Section: Objects, Interfaces, and Type Aliases

Combine shapes with intersection

typescript
typescript
type Audit = { createdAt: Date };
type Customer = { id: string; name: string };

type AuditedCustomer = Customer & Audit;
Explanation

Intersection types are useful when enriching objects with shared metadata.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Objects, Interfaces, and Type Aliases
Define an interface
Use an interface to model a reusable object shape.
OpenIn sheettypescriptsame section
Define a type alias
Use a type alias for unions, objects, tuples, or helpers.
OpenIn sheettypescriptsame section
Extend an interface
Compose interfaces with inheritance.
OpenIn sheettypescriptsame section
Mark properties readonly
Prevent mutation through the type system.
OpenIn sheettypescriptsame section
Use an index signature
Type dictionary-like objects with dynamic keys.
OpenIn sheettypescriptsame section
Initialize tsconfig
Create a starter tsconfig.json in the current project.
OpenIn sheetbash1 tag match