Skip to content

Commit

Permalink
test(typescript): avoid the void
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jun 13, 2021
1 parent 7a99454 commit e89c39c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { Octokit } from "../src";

export function expectType<T>(what: T) {}

export function pluginsTest() {
// `octokit` instance does not permit unknown keys
const octokit = new Octokit();
Expand Down Expand Up @@ -36,4 +38,18 @@ export function pluginsTest() {
octokitWithPluginAndDefaults.foo;
// @ts-expect-error `.unknown` should not be typed as `any`
octokitWithPluginAndDefaults.unknown;

// https://github.com/octokit/octokit.js/issues/2115
const OctokitWithVoidAndNonVoidPlugins = Octokit.plugin(
() => ({ foo: "foo" }),
() => {},
() => ({ bar: "bar" })
);
const octokitWithVoidAndNonVoidPlugins =
new OctokitWithVoidAndNonVoidPlugins();

// @ts-expect-error octokitWithVoidAndNonVoidPlugins must never be `void`, even if one of the plugins returns `void`
expectType<void>(octokitWithVoidAndNonVoidPlugins);
expectType<string>(octokitWithVoidAndNonVoidPlugins.foo);
expectType<string>(octokitWithVoidAndNonVoidPlugins.bar);
}

0 comments on commit e89c39c

Please sign in to comment.