Skip to content

Commit

Permalink
feat(typescript): types for `octokit.hook.{before,after,error,wrap}("…
Browse files Browse the repository at this point in the history
…request", () => {})` methods
  • Loading branch information
gr2m committed Mar 5, 2021
1 parent 66910dc commit c245588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createTokenAuth } from "@octokit/auth-token";

import {
Constructor,
Hooks,
OctokitOptions,
OctokitPlugin,
RequestParameters,
Expand Down Expand Up @@ -70,7 +71,7 @@ export class Octokit {
}

constructor(options: OctokitOptions = {}) {
const hook = new Collection();
const hook = new Collection<Hooks>();
const requestDefaults: Required<RequestParameters> = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
Expand Down Expand Up @@ -175,7 +176,7 @@ export class Octokit {
error: (message: string, additionalInfo?: object) => any;
[key: string]: any;
};
hook: HookCollection;
hook: HookCollection<Hooks>;

// TODO: type `octokit.auth` based on passed options.authStrategy
auth: (...args: unknown[]) => Promise<unknown>;
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as OctokitTypes from "@octokit/types";
import { RequestError } from "@octokit/request-error";

import { Octokit } from ".";

Expand Down Expand Up @@ -49,3 +50,11 @@ export type OctokitPlugin = (
octokit: Octokit,
options: OctokitOptions
) => { [key: string]: any } | void;

export type Hooks = {
request: {
Options: OctokitTypes.EndpointOptions;
Result: OctokitTypes.OctokitResponse<any>;
Error: RequestError | Error;
};
};

0 comments on commit c245588

Please sign in to comment.