diff --git a/package.json b/package.json index 2f7cf87..3d56773 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "types": "./index.d.ts", "exports": "./index.js", "scripts": { - "test": "npm run test:code && npm run test:dts && npm run test:coverage", + "test": "npm run test:code && npm run test:dts && npm run test:ts && npm run test:coverage", "test:code": "c8 node test.js", "test:coverage": "c8 check-coverage", - "test:dts": "for d in tests/js/* ; do tsd $d; done", - "test:ts": "for d in tests/ts/*/tsconfig.json ; do echo $d; tsc -p $d; done" + "test:dts": "for d in tests/js/* ; do echo $d; tsd $d; if [ $? -eq 0 ]; then echo ok; else exit 1; fi; done", + "test:ts": "for d in tests/ts/*/tsconfig.json ; do echo $d; tsc -p $d; if [ $? -eq 0 ]; then echo ok; else exit 1; fi; done" }, "renovate": { "extends": [ diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 415c8f6..21a2d98 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -4,12 +4,7 @@ import { RequestInterface } from "./request"; * Global Octokit interfaces that can be extended as needed. */ export namespace Octokit { - interface Options { - /** - * GitHub API Version. Defaults to "github.com" - */ - version?: TVersion; - + interface Options { /** * GitHub's REST API base URL. Defaults to https://api.github.com * @@ -115,7 +110,7 @@ export namespace Octokit { export declare class Octokit< TVersion extends keyof Octokit.ApiVersions = "github.com", - TOptions extends Octokit.Options = Octokit.Options + TOptions extends Octokit.Options = Octokit.Options > { /** * Pass one or multiple plugin functions to extend the `Octokit` class. @@ -165,7 +160,7 @@ export declare class Octokit< static withDefaults< PredefinedOptionsOne, ClassOne extends Constructor< - Octokit & PredefinedOptionsOne> + Octokit > & ClassWithPlugins, TVersion extends keyof Octokit.ApiVersions = "github.com" @@ -209,9 +204,9 @@ export declare class Octokit< /** * Options passed to the constructor combined with the constructor defaults */ - options: TOptions; + options: { version: TVersion } & TOptions; - constructor(options: TOptions); + constructor(options: { version?: TVersion } & TOptions); request: RequestInterface; } diff --git a/tests/js/ghes-3.0/index.d.ts b/tests/js/ghes-3.0-class/index.d.ts similarity index 100% rename from tests/js/ghes-3.0/index.d.ts rename to tests/js/ghes-3.0-class/index.d.ts diff --git a/tests/js/ghes-3.0/index.js b/tests/js/ghes-3.0-class/index.js similarity index 100% rename from tests/js/ghes-3.0/index.js rename to tests/js/ghes-3.0-class/index.js diff --git a/tests/js/ghes-3.0/index.test-d.ts b/tests/js/ghes-3.0-class/index.test-d.ts similarity index 100% rename from tests/js/ghes-3.0/index.test-d.ts rename to tests/js/ghes-3.0-class/index.test-d.ts diff --git a/tests/js/ghes-3.1-class/index.d.ts b/tests/js/ghes-3.1-class/index.d.ts new file mode 100644 index 0000000..9c91f10 --- /dev/null +++ b/tests/js/ghes-3.1-class/index.d.ts @@ -0,0 +1,15 @@ +import { ExtendOctokitWith, Octokit } from "@octokit-next/core"; + +import "@octokit-next/types-rest-api-ghes-3.1"; + +export const OctokitGhes31: ExtendOctokitWith< + Octokit<"ghes-3.1">, + { + defaults: { + baseUrl: string; + }; + } +>; + +// support import to be used as a class instance type +export type OctokitGhes31 = typeof OctokitGhes31; diff --git a/tests/js/ghes-3.1/index.js b/tests/js/ghes-3.1-class/index.js similarity index 100% rename from tests/js/ghes-3.1/index.js rename to tests/js/ghes-3.1-class/index.js diff --git a/tests/js/ghes-3.1-class/index.test-d.ts b/tests/js/ghes-3.1-class/index.test-d.ts new file mode 100644 index 0000000..e46a547 --- /dev/null +++ b/tests/js/ghes-3.1-class/index.test-d.ts @@ -0,0 +1,27 @@ +import { expectType, expectNotType } from "tsd"; + +import { OctokitGhes31 } from "./index.js"; + +export async function test() { + new OctokitGhes31({}); + + const octokit = new OctokitGhes31({ + baseUrl: "https://github.acme-inc.com/api/v3", + }); + + const emojisResponseGhes31 = await octokit.request("GET /emojis"); + expectType(emojisResponseGhes31.data["+1"]); + expectType(emojisResponseGhes31.data["-1"]); + expectType(emojisResponseGhes31.data["ghes-only"]); + expectType(emojisResponseGhes31.data["dotcom-only"]); + + expectType(await octokit.request("GET /dotcom-only")); + expectNotType(await octokit.request("GET /new-endpoint")); + + const { headers } = await octokit.request("GET /emojis"); + expectType(headers["x-github-enterprise-version"]); + expectType(headers["x-dotcom-only"]); + + expectNotType(await octokit.request("GET /ghes-only")); + expectNotType(await octokit.request("GET /new-ghes-only")); +} diff --git a/tests/js/ghes-3.1/index.d.ts b/tests/js/ghes-3.1/index.d.ts index 9c91f10..cb0ff5c 100644 --- a/tests/js/ghes-3.1/index.d.ts +++ b/tests/js/ghes-3.1/index.d.ts @@ -1,15 +1 @@ -import { ExtendOctokitWith, Octokit } from "@octokit-next/core"; - -import "@octokit-next/types-rest-api-ghes-3.1"; - -export const OctokitGhes31: ExtendOctokitWith< - Octokit<"ghes-3.1">, - { - defaults: { - baseUrl: string; - }; - } ->; - -// support import to be used as a class instance type -export type OctokitGhes31 = typeof OctokitGhes31; +export {}; diff --git a/tests/js/ghes-3.1/index.test-d.ts b/tests/js/ghes-3.1/index.test-d.ts index e46a547..526027f 100644 --- a/tests/js/ghes-3.1/index.test-d.ts +++ b/tests/js/ghes-3.1/index.test-d.ts @@ -1,27 +1,18 @@ import { expectType, expectNotType } from "tsd"; -import { OctokitGhes31 } from "./index.js"; +import { Octokit } from "@octokit-next/core"; -export async function test() { - new OctokitGhes31({}); +import "@octokit-next/types-rest-api-ghes-3.1"; - const octokit = new OctokitGhes31({ - baseUrl: "https://github.acme-inc.com/api/v3", +export async function test() { + const octokit = new Octokit({ + version: "ghes-3.1", }); - const emojisResponseGhes31 = await octokit.request("GET /emojis"); - expectType(emojisResponseGhes31.data["+1"]); - expectType(emojisResponseGhes31.data["-1"]); - expectType(emojisResponseGhes31.data["ghes-only"]); - expectType(emojisResponseGhes31.data["dotcom-only"]); - - expectType(await octokit.request("GET /dotcom-only")); - expectNotType(await octokit.request("GET /new-endpoint")); - - const { headers } = await octokit.request("GET /emojis"); - expectType(headers["x-github-enterprise-version"]); - expectType(headers["x-dotcom-only"]); + const dotcomOnlyResponse = await octokit.request("GET /dotcom-only"); + expectType(dotcomOnlyResponse); - expectNotType(await octokit.request("GET /ghes-only")); - expectNotType(await octokit.request("GET /new-ghes-only")); + const ghesOnlyResponse = await octokit.request("GET /ghes-only"); + expectType(ghesOnlyResponse.data.ok); + expectType(ghesOnlyResponse.headers["x-dotcom-only"]); }