Course contentsShow
← TypeScript
Lesson 339 of 1,7968. Interfaces vs Type AliasesFree lesson

Basic Interface Syntax

Declare interfaces with property names, types, and optional method signatures.

Basic Interface Syntax

You'll learn: How to declare interfaces with property names, types, and optionally define method signatures.

What Is Interface Syntax?

An interface is a named structure that describes the shape of an object. You define it using the interface keyword, followed by a name (typically PascalCase), then curly braces containing property names and their types.

Think of it like a blueprint: it tells TypeScript exactly what properties an object should have and what types those properties must be.

Basic Property Syntax

Here's the fundamental structure:

interface User {
  name: string;
  age: number;
}

Each property lists the name, a colon, then the type. You can use semicolons (;) or commas (,) to separate properties—both work identically.

Adding Method Signatures

Interfaces can also describe methods. You have two syntax options:

interface Calculator {
  // Method shorthand
  add(a: number, b: number): number;
  
  // Property function signature
  subtract: (a: number, b: number) => number;
}

Both styles declare that the object must have callable properties. The first (method shorthand) is more common for interfaces.

Using Your Interface

Once declared, use the interface name as a type:

const admin: User = {
  name: "Alice",
  age: 30
};

TypeScript will enforce that admin has exactly the properties defined in User with the correct types.

Key Takeaway: Interfaces use interface Name { } syntax to declare object shapes with property names, types, and optional method signatures—creating reusable, named type contracts for your objects.