Skip to main content

index/functions/buildSafePaginationOptions.md

buildSafePaginationOptions(options): BasePaginationOptions

Safely build pagination options without passing undefined

This helper ensures that optional pagination fields are only included when they have actual values, complying with exactOptionalPropertyTypes.

Parameters​

ParameterTypeDescription
optionsPartial<BasePaginationOptions>Partial pagination options (may have undefined values)

Returns​

BasePaginationOptions

Clean pagination options object without undefined properties

Example​

const cursor = getCursorFromSomewhere() || undefined;
const pageSize = getPageSize();

// This would cause TS2379 error:
// const options: BasePaginationOptions = { cursor, pageSize };

// Use this helper instead:
const options = buildSafePaginationOptions({
cursor, // May be undefined
pageSize
});
// Result has no undefined values

Since​

8.0.0