0Pricing
TypeScript Academy · Lesson

Reusable patterns for data models

Apply generic patterns to real models: Paginated , Result , DTOs with Pick/Omit/Partial, and maps keyed by id.

Intro

Goal: Package common data shapes as generic types so you reuse structure without losing type safety.

  • Paginated<T>
  • Result<T,E>
  • DTOs with Pick/Omit/Partial
  • Maps keyed by id

Paginated<T>

Paginated<T> centralizes metadata and keeps item type T precise for lists.

type Paginated<T> = {
  items: T[];
  total: number;
  page: number;
  pageSize: number;
};

type User = { id: number; name: string };

const page1: Paginated<User> = {
  items: [{ id: 1, name: "Ada" }],
  total: 10,
  page: 1,
  pageSize: 5,
};

console.log(page1.items[0].name);

All lessons in this course

  1. Generic interfaces & type aliases
  2. Conditional Types (intro) & distribution over unions
  3. Reusable patterns for data models
← Back to TypeScript Academy