Skip to content
New issue

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

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

Already on GitHub? # to your account

@actions/github cannot declare variable of type GitHub. It says it´s not exported #637

Closed
brpaz opened this issue Nov 15, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@brpaz
Copy link

brpaz commented Nov 15, 2020

Describe the bug

I am trying to declare a variable of the type "octokit" but I can´t get it working.

I have seen some code and also #365 which shows I could do like:

import { GitHub } from "@actions/github"

and then just declare my variable as: const octokit: GitHub

But this doesn´t work. Typescript complains the variable is not exported.

Module '"../node_modules/@actions/github/lib/github"' declares 'GitHub' locally, but it is not exported

To Reproduce

import { GitHub } from "@actions/github"

const octokit = new GitHub("mytoken");

Expected behavior
The GitHub type should be exported, so I can specify the type of my variables

Additional context

Using version 4.0.0. It works with version 2.2.0. I guess the interface changed. Still I have to be able to declare my variable with correct type.

@brpaz brpaz added the bug Something isn't working label Nov 15, 2020
@peaceiris
Copy link
Contributor

FYI. peaceiris/actions-label-commenter@8927674

@jhuleatt
Copy link

jhuleatt commented Dec 23, 2020

I believe this is due to an api change. I worked around this by doing the following (which is now the recommended way in the README):

import { getOctokit } from "@actions/github";

const octokit = getOctokit("mytoken");

in other modules that might need to know the type of octokit, I do:

import type { GitHub } from "@actions/github/lib/utils";

export async function createCheck(
  octokit: InstanceType<typeof GitHub>
) {
  // ...
}

@brpaz
Copy link
Author

brpaz commented Dec 25, 2020

Thanks. I saw the README, but I wanted to inject the Ocotkit into my service. I was missing how I could declare the type like this InstanceType<typeof GitHub>. Thanks.

@brpaz brpaz closed this as completed Dec 25, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants