Dev Helpers
← Back

Make an empty page of a known type

Make an empty page of a known 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((<T,>(): Page<T> => ({ items: [], next: null }))<string>());

Sample output

{ items: [], next: null }