Skip to content

Commit

Permalink
test(typescript): do not permit unknown keys on octokit instance
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Apr 3, 2021
1 parent b753efb commit f7fa8fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint": "prettier --check '{src,test}/**/*.{ts,md}' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage"
"test": "jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals test/typescript-validate.ts"
},
"repository": "github:octokit/core.js",
"keywords": [
Expand Down
39 changes: 39 additions & 0 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ************************************************************
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************

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

export function pluginsTest() {
// `octokit` instance does not permit unknown keys
const octokit = new Octokit();

// @ts-expect-error Property 'unknown' does not exist on type 'Octokit'.(2339)
octokit.unknown;

const OctokitWithDefaults = Octokit.defaults({});
const octokitWithDefaults = new OctokitWithDefaults();

// Error: `octokitWithDefaults` does permit unknown keys
// @ts-expect-error `.unknown` should not be typed as `any`
octokitWithDefaults.unknown;

const OctokitWithPlugin = Octokit.plugin(() => ({}));
const octokitWithPlugin = new OctokitWithPlugin();

// Error: `octokitWithPlugin` does permit unknown keys
// @ts-expect-error `.unknown` should not be typed as `any`
octokitWithPlugin.unknown;

const OctokitWithPluginAndDefaults = Octokit.plugin(() => ({
foo: 42,
})).defaults({
baz: "daz",
});

const octokitWithPluginAndDefaults = new OctokitWithPluginAndDefaults();

octokitWithPluginAndDefaults.foo;
// @ts-expect-error `.unknown` should not be typed as `any`
octokitWithPluginAndDefaults.unknown;
}

0 comments on commit f7fa8fb

Please sign in to comment.