Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the version parameter work with the static .withDefaults() method #11

Closed
gr2m opened this issue Aug 9, 2021 · 2 comments · Fixed by #24
Closed

Make the version parameter work with the static .withDefaults() method #11

gr2m opened this issue Aug 9, 2021 · 2 comments · Fixed by #24

Comments

@gr2m
Copy link
Contributor

gr2m commented Aug 9, 2021

In a nutshell I want octokitGhes31_v1 and octokitGhes31_v2 to have both the internal version type set to "ghes-3.1."

const OctokitWithDefaultVersion = Octokit.withDefaults({ version: "ghes-3.1" });

const octokitGhes31_v1 = new OctokitWithDefaultVersion();
const octokitGhes31_v2 = new Octokit({ version: "ghes-3.1" });

Here is a TypeScript test file that should compile, but currently has several errors

import { Octokit } from "@octokit-next/core";

import "@octokit-next/types-rest-api-ghes-3.0";

export async function run() {
  const octokit = new Octokit({
    version: "ghes-3.1",
  });

  const response = await octokit.request("GET /ghes-only");

  expectType<boolean>(response.data.ok);

  const OctokitGHES31 = Octokit.withDefaults({
    version: "ghes-3.1",
  });
  const octokitGhes31 = new OctokitGHES31();
  expectType<never>(await octokitGhes31.request("GET /dotcom-only"));

  const octokitGhes30ViaConstructorOptions = new OctokitGHES31({
    version: "ghes-3.0",
  });
  expectType<never>(
    await octokitGhes30ViaConstructorOptions.request("GET /new-ghes-only")
  );

  const OctokitGHES30 = OctokitGHES31.withDefaults({
    version: "ghes-3.0",
  });
  const octokitGhes30ViaChainedDefaults = new OctokitGHES30();
  expectType<never>(
    await octokitGhes30ViaChainedDefaults.request("GET /new-ghes-only")
  );
}

function expectType<T>(value: T): void {}
@gr2m
Copy link
Contributor Author

gr2m commented Aug 13, 2021

See also #20. version and authStrategy are special options that way

@github-actions
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant