Skip to main content
Module 2 · Lesson 1 of 23/22 in the course~15 min
Module lessons (1/2)

Type alias vs Interfaces

Lesson preview6 hands-on exercises readyCourse TypeScript · Module 2 — Types and Interfaces

Model objects with interface and type, optional fields, readonly and compositional extension.

What you'll learn in this lesson

  • Define expressive object shapes with interface and type.
  • Distinguish optional fields (email?: string) from mandatory properties and apply readonly on identity fields.
  • Extend contracts via inheritance between interfaces (extends) or via intersection (&) between type aliases.
  • Recognize the concrete differences between interface and type (unions, primitives, declaration merging).

Overview

When structures grow beyond a few values, repeating inline { id: number; name: string } becomes brittle and verbose. TypeScript offers two complementary tools for naming a shape: interface and type alias.

An interface describes the form that an object (or a class via implements) must respect. Supports optional (?) and read-only (readonly) fields.

Sections covered in this lesson

  1. 1interface: Contracts for extensible objects
  2. 2type alias: maximum expressiveness
  3. 3Guided practice
  4. 4Check for understanding
Pro Lesson · Module 2 — Types and Interfaces

Unlock "Type alias vs Interfaces" and the full Course TypeScript curriculum

Model objects with interface and type, optional fields, readonly and compositional extension.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.