0Pricing
TypeScript Academy · Lesson

Default Type Parameters

Provide fallback types when no argument is given.

Welcome

Default type parameters provide a fallback type when the caller does not specify a type argument. They make generic APIs more ergonomic.

Default Syntax

Add `= DefaultType` after the type parameter name to set a default.
interface Container<T = string> {
  value: T;
}
const c: Container = { value: 'hello' }; // T defaults to string
const n: Container<number> = { value: 42 };

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