Paginate a List with Typed Pages
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Export a generic type Page<T>: { items: T[]; page: number; totalPages: number; hasNext: boolean }. Then write paginate(items, page, size): return that page of items (pages count from 1), how many pages there are (at least 1, so an empty list has one empty page) and whether a later page exists; a page past the end has no items. Type it so the page's items keep the list's own type and page and size must be numbers.
Your code must pass
- Returns the right slice
- Works out totalPages and hasNext
- Has no type errors
- Items keep the list's type
- Rejects a page that isn't a number