TypeScript Cheat Sheet/Define an interface

Use an interface to model a reusable object shape.

Section: Objects, Interfaces, and Type Aliases

Define an interface

typescript
typescript
interface User {
  id: number;
  name: string;
  email?: string;
}
Explanation

Interfaces are commonly used for object shapes, especially public APIs.

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
Extend an interface
Compose interfaces with inheritance.
OpenIn sheettypescriptsame section
Use an index signature
Type dictionary-like objects with dynamic keys.
OpenIn sheettypescriptsame section
Define a type alias
Use a type alias for unions, objects, tuples, or helpers.
OpenIn sheettypescriptsame section
Combine shapes with intersection
Merge multiple types into one.
OpenIn sheettypescriptsame section
Mark properties readonly
Prevent mutation through the type system.
OpenIn sheettypescriptsame section
Annotate object shapes
Describe the expected properties of an object.
OpenIn sheettypescript2 tag match