0Pricing
TypeScript Academy · Lesson

Generic Interfaces and Type Aliases

Apply generics to interfaces and custom types.

Welcome

Generics are not limited to functions. Interfaces and type aliases also accept type parameters, making them reusable across many types.

Generic Interface Syntax

Add `` after the interface name to make it generic. Use T in property types and method signatures.
interface Box<T> {
  value: T;
  unwrap(): T;
}
const box: Box<number> = { value: 42, unwrap() { return this.value; } };

All lessons in this course

  1. Generic Functions: Type Parameters
  2. Generic Interfaces and Type Aliases
  3. Generic Constraints with extends
  4. Default Type Parameters
← Back to TypeScript Academy