TypeScript · Types and shapes

Interface

Describes an object shape. Interfaces can be extended and declared twice; type aliases cannot.

Syntax
interface User { … }

Example

Example
interface User {
  id: string;
  name: string;
}
const user: User = { id: "u1", name: "Ada" };

More in this group

any Array types enums Function type Literal type never null and undefined Optional property

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course