Dev Helpers
← Back

Read a page's item type

Read a page's item type using TypeScript.

Open this example in the interactive library

Source code

type Page<T> = { items: T[]; next: string | null };
const page: Page<{ id: number }> = { items: [{ id: 1 }, { id: 2 }], next: "2" };
console.log(((item: (typeof page.items)[number]) => item.id)(page.items[0]));

Sample output

1