Skip to content

Add Generic Typedefs to Paginator for Type Safety #247

@nickspaargaren

Description

@nickspaargaren

Hi! 👋

We areusing trojs/paginator (^3.1.8) and noticed that the current JSDoc typedefs don’t fully support generics. Right now, items is typed as object[] which makes type inference any and doesn’t carry through the item type to Pagination.data.

It would be great if trojs/paginator supported generic types so that TypeScript (or editors with JSDoc support) could infer the type of items and pagination objects correctly. For example:

/**
 * @template T
 * @typedef {Object} Pagination
 * @property {PaginationLinks} cursors
 * @property {number} count
 * @property {number} pages
 * @property {number} size
 * @property {number|null} page
 * @property {T[]} items
 */

and

/**
 * @template T
 * @returns {Paginator<T>}
 */
const PaginatorBuilder = ({ items, page, size, count, url, sortColumn, sortDirection }) => { ... }

/** @type {Pagination<InvoiceType>} */
const result = Paginator({
  items: invoices,
  page,
  size,
  count
}).data

Would you consider adding this generic support to trojs/paginator?

Thanks! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions