Skip to content

Commit

Permalink
style: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Feb 18, 2025
1 parent 0e2a88e commit 7994b94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
18 changes: 6 additions & 12 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import type { PaginatingEndpoints } from "./generated/paginating-endpoints.js";
// : never
// : never;

type PaginationMetadataKeys = "repository_selection" | "total_count" | "incomplete_results";
type PaginationMetadataKeys =
| "repository_selection"
| "total_count"
| "incomplete_results";

// https://stackoverflow.com/a/58980331/206879
type KnownKeys<T> = Extract<
Expand All @@ -38,10 +41,7 @@ type KnownKeys<T> = Extract<
? U
: never,
// Exclude keys that are known to not contain the data
Exclude<
keyof T,
PaginationMetadataKeys
>
Exclude<keyof T, PaginationMetadataKeys>
>;
type KeysMatching<T, V> = {
[K in keyof T]: T[K] extends V ? K : never;
Expand All @@ -60,13 +60,7 @@ type GetResultsType<T> = T extends { data: any[] }
type GetPaginationKeys<T> = T extends { data: any[] }
? {}
: T extends { data: object }
? Pick<
T["data"],
Extract<
keyof T["data"],
PaginationMetadataKeys
>
>
? Pick<T["data"], Extract<keyof T["data"], PaginationMetadataKeys>>
: never;

// Ensure that the type always returns the paginated results and not a mix of paginated results and the response object
Expand Down
7 changes: 5 additions & 2 deletions test/validate-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ export async function requestMethodWithNamespacedResponse() {

// https://github.com/octokit/plugin-paginate-rest.js/issues/661
// Ensure the endpoints that return an array don't have an extra `OctokitResponse` in the data
type Package = PaginatingEndpoints["GET /orgs/{org}/packages/{package_type}/{package_name}/versions"]["response"]["data"][0];
type Package =
PaginatingEndpoints["GET /orgs/{org}/packages/{package_type}/{package_name}/versions"]["response"]["data"][0];
export async function requestWithArrayResponse() {
const results = await octokit.paginate("GET /orgs/{org}/packages/{package_type}/{package_name}/versions");
const results = await octokit.paginate(
"GET /orgs/{org}/packages/{package_type}/{package_name}/versions",
);
for (const result of results) {
const pkg: Package = result;
console.log(pkg.name);
Expand Down

0 comments on commit 7994b94

Please sign in to comment.