Skip to content

Commit

Permalink
fix(types): add back the pagination keys (#653)
Browse files Browse the repository at this point in the history
Fixes #652
  • Loading branch information
wolfy1339 authored Feb 13, 2025
1 parent 41876f4 commit 8b8c500
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,23 @@ type GetResultsType<T> = T extends { data: any[] }
? T["data"][KnownKeysMatching<T["data"], any[]>]
: never;

// Ensure that the type always returns the paginated results and not a mix of paginated results and the response object
type NormalizeResponse<T> = Omit<T, "data"> & { data: GetResultsType<T> };
// Extract the pagination keys from the response object in order to return them alongside the paginated results
type GetPaginationKeys<T> = T extends { data: any[] }
? T
: T extends { data: object }
? Pick<
T["data"],
Extract<
keyof T["data"],
"repository_selection" | "total_count" | "incomplete_results"
>
>
: never;

// Ensure that the type always returns the paginated results and not a mix of paginated results and the response object
type NormalizeResponse<T> = Omit<T, "data"> & {
data: GetResultsType<T> & GetPaginationKeys<T>;
};
type DataType<T> = "data" extends keyof T ? T["data"] : unknown;

export interface MapFunction<
Expand Down

0 comments on commit 8b8c500

Please sign in to comment.