diff --git a/src/RequestInterface.ts b/src/RequestInterface.ts index 968c51790..d512c4dcd 100644 --- a/src/RequestInterface.ts +++ b/src/RequestInterface.ts @@ -3,8 +3,15 @@ import type { OctokitResponse } from "./OctokitResponse"; import type { RequestParameters } from "./RequestParameters"; import type { Route } from "./Route"; -import type { Endpoints } from "./generated/Endpoints"; +import type { Endpoints, Simplify } from "./generated/Endpoints"; +/** + * Parameters that can be passed into `request(route, parameters)` or `endpoint(route, parameters)` methods. + * This type represents the options when `request.parseSuccessResponseBody` is set to `false`. + */ +type StreamBodyOption = Simplify< + RequestParameters & { request: { parseSuccessResponseBody: false } } +>; export interface RequestInterface { /** * Sends a request based on endpoint options @@ -17,6 +24,38 @@ export interface RequestInterface { : { url: string }), ): Promise>; + /** + * Sends a request based on endpoint options + * + * @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. + */ + ( + options: O & { method?: string } & ("url" extends keyof D + ? { url?: string } + : { url: string }), + ): Promise>>; + + /** + * Sends a request based on endpoint options + * + * @param {string} route Request method + URL. Example: `'GET /orgs/{org}'` + * @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. + */ + ( + route: keyof Endpoints | R, + options?: R extends keyof Endpoints + ? Endpoints[R]["parameters"] & O + : StreamBodyOption, + ): R extends keyof Endpoints + ? Promise< + OctokitResponse< + ReadableStream< + Exclude> + > + > + > + : Promise>>; + /** * Sends a request based on endpoint options * diff --git a/test.ts b/test.ts index 2794e10dc..4c9ac95a1 100644 --- a/test.ts +++ b/test.ts @@ -54,10 +54,7 @@ assertPaginate(checkRunsRoute); const listForRef = {} as { ( params?: RequestParameters & - Omit< Endpoints["GET /repos/{owner}/{repo}/commits/{ref}/check-runs"]["parameters"], - "baseUrl" | "headers" | "mediaType" - > ): Promise; defaults: RequestInterface["defaults"]; endpoint: EndpointInterface<{