From e89c39ce5af0f3ec6659cb3c7ed556db8de6ff3c Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Tue, 8 Jun 2021 00:46:17 -0700 Subject: [PATCH] test(typescript): avoid the void --- test/typescript-validate.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts index 0cf3eb9ae..979968575 100644 --- a/test/typescript-validate.ts +++ b/test/typescript-validate.ts @@ -4,6 +4,8 @@ import { Octokit } from "../src"; +export function expectType(what: T) {} + export function pluginsTest() { // `octokit` instance does not permit unknown keys const octokit = new Octokit(); @@ -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(octokitWithVoidAndNonVoidPlugins); + expectType(octokitWithVoidAndNonVoidPlugins.foo); + expectType(octokitWithVoidAndNonVoidPlugins.bar); }