Dev Helpers
← Back

Construct a final page from an iterable

Construct a final page from an iterable 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,>(items: Iterable<T>): Page<T> => ({ items: [...items], next: null }))(
    new Set(["a", "b"]),
  ),
);

Sample output

{ items: [ 'a', 'b' ], next: null }