-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(typescript): infer
octokit
types from the version
option pass…
…ed to the `Octokit` constructor (#10)
- Loading branch information
Showing
10 changed files
with
61 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>(emojisResponseGhes31.data["+1"]); | ||
expectType<string>(emojisResponseGhes31.data["-1"]); | ||
expectType<string>(emojisResponseGhes31.data["ghes-only"]); | ||
expectType<never>(emojisResponseGhes31.data["dotcom-only"]); | ||
|
||
expectType<never>(await octokit.request("GET /dotcom-only")); | ||
expectNotType<never>(await octokit.request("GET /new-endpoint")); | ||
|
||
const { headers } = await octokit.request("GET /emojis"); | ||
expectType<string>(headers["x-github-enterprise-version"]); | ||
expectType<never>(headers["x-dotcom-only"]); | ||
|
||
expectNotType<never>(await octokit.request("GET /ghes-only")); | ||
expectNotType<never>(await octokit.request("GET /new-ghes-only")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>(emojisResponseGhes31.data["+1"]); | ||
expectType<string>(emojisResponseGhes31.data["-1"]); | ||
expectType<string>(emojisResponseGhes31.data["ghes-only"]); | ||
expectType<never>(emojisResponseGhes31.data["dotcom-only"]); | ||
|
||
expectType<never>(await octokit.request("GET /dotcom-only")); | ||
expectNotType<never>(await octokit.request("GET /new-endpoint")); | ||
|
||
const { headers } = await octokit.request("GET /emojis"); | ||
expectType<string>(headers["x-github-enterprise-version"]); | ||
expectType<never>(headers["x-dotcom-only"]); | ||
const dotcomOnlyResponse = await octokit.request("GET /dotcom-only"); | ||
expectType<never>(dotcomOnlyResponse); | ||
|
||
expectNotType<never>(await octokit.request("GET /ghes-only")); | ||
expectNotType<never>(await octokit.request("GET /new-ghes-only")); | ||
const ghesOnlyResponse = await octokit.request("GET /ghes-only"); | ||
expectType<boolean>(ghesOnlyResponse.data.ok); | ||
expectType<never>(ghesOnlyResponse.headers["x-dotcom-only"]); | ||
} |