Skip to content

Commit

Permalink
feat: add return types for request.parseSuccessResponseBody
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Feb 9, 2024
1 parent fa1e25b commit 2f09fdc
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/RequestInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ 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<D extends object = object> {
/**
* Sends a request based on endpoint options
Expand All @@ -16,7 +21,34 @@ export interface RequestInterface<D extends object = object> {
? { url?: string }
: { url: string }),
): Promise<OctokitResponse<T>>;


/**
* 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`.
*/
<T = any, O extends StreamBodyOption = StreamBodyOption>(
options: O & { method?: string } & ("url" extends keyof D
? { url?: string }
: { url: string }),
): Promise<OctokitResponse<ReadableStream<T>>>;

/**
* 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`.
*/
<R extends Route, O extends StreamBodyOption>(
route: keyof Endpoints | R,
options?: R extends keyof Endpoints
? Endpoints[R]["parameters"] & O
: StreamBodyOption,
): R extends keyof Endpoints
? Promise<Endpoints[R]["response"]>
: Promise<OctokitResponse<ReadableStream<any>>>;

/**
* Sends a request based on endpoint options
*
Expand Down

0 comments on commit 2f09fdc

Please sign in to comment.