octokit.js: [BUG]: Typescript error on paginate string input
What happened?
When using octokit.paginate, Typescript errors saying (I think?) that it does not accept a string as the first input. My understanding based on the docs and @octokit/types code is that this input can be a string, and I have confirmed that the code builds and runs if I ignore this error with // @ts-ignore. I initially had this same code but using octokit.request instead and did not have the error.
const alerts: Array<DependabotAlert> = await octokit.paginate(
"GET /orgs/{org}/dependabot/alerts",
{
org: GITHUB_ORG,
per_page: 100,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
},
(response) =>
response.data.map(
(item) =>
<DependabotAlert>{
createdAt: item.created_at,
cve: item.security_advisory.cve_id,
ecosystem: item.security_vulnerability.package.ecosystem,
number: item.number,
package: item.security_vulnerability.package.name,
repository: item.repository.name,
severity: item.security_vulnerability.severity,
state: item.state,
url: item.html_url,
}
)
);
Note: DependabotAlert is my own custom type that defines the resulting output.
What happened: Typescript error when building
No overload matches this call.
...
Argument of type 'string' is not assignable to parameter of type 'RequestInterface<object>'. ts(2769)
What I expect to happen: No Typescript error. Should build and run with "GET /orgs/{org}/dependabot/alerts" (or any string) as input.
Workaround: Add // @ts-ignore above this function call so that Typescript will ignore it and build anyways.
Versions
nodejs 16.20.0 octokit 2.0.14 @octokit/types 9.0.0 (as a sub-dependency of octokit) typescript 5.0.4
Relevant log output
error TS2769: No overload matches this call.
Overload 1 of 9, '(route: "GET /orgs/{org}/dependabot/alerts", parameters: { org: string; } & { state?: string | undefined; severity?: string | undefined; ecosystem?: string | undefined; package?: string | undefined; ... 7 more ...; per_page?: number | undefined; }, mapFn: MapFunction<...>): Promise<...>', gave the following error.
Argument of type '{ org: string; per_page: number; headers: { "X-GitHub-Api-Version": string; }; }' is not assignable to parameter of type '{ org: string; } & { state?: string | undefined; severity?: string | undefined; ecosystem?: string | undefined; package?: string | undefined; scope?: "development" | "runtime" | undefined; ... 6 more ...; per_page?: number | undefined; }'.
Object literal may only specify known properties, and 'headers' does not exist in type '{ org: string; } & { state?: string | undefined; severity?: string | undefined; ecosystem?: string | undefined; package?: string | undefined; scope?: "development" | "runtime" | undefined; ... 6 more ...; per_page?: number | undefined; }'.
Overload 2 of 9, '(request: RequestInterface<object>, parameters: string, mapFn: MapFunction<NormalizeResponse<OctokitResponse<any>>, DependabotAlert[]>): Promise<...>', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'RequestInterface<object>'.
9 const alerts: Array<DependabotAlert> = await octokit.paginate(
~~~~~~~~~~~~~~~~~
10 "GET /orgs/{org}/dependabot/alerts",
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
32 )
~~~~~~~
33 );
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 22 (14 by maintainers)
Indeed it does look like it’s the headers option.
I don’t understand why.
As stated in a previous comment, you can use the
octokit.restmethods with pagination and it works fine. https://github.com/octokit/octokit.js/issues/2439#issuecomment-1555050667This code snippet works, it’s simply when passing the route as a URL that it doesn’t accept request parameters
This is probably due to the fact that OpenAPI updates haven’t been made on the regular. This should be fixed when https://github.com/octokit/openapi/pull/328 is merged, and the resulting schema updates trickle through all the modules