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

TypeScript errors in github/lib/github.d.ts #199

Closed
RyanCavanaugh opened this issue Oct 31, 2019 · 7 comments
Closed

TypeScript errors in github/lib/github.d.ts #199

RyanCavanaugh opened this issue Oct 31, 2019 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@RyanCavanaugh
Copy link

Describe the bug

The shipped github.d.ts file contains errors. The originating code is here: https://github.com/actions/toolkit/blob/master/packages/github/src/github.ts

To Reproduce
Steps to reproduce the behavior:

  1. npm init -y
  2. tsc --init
  3. Add a.ts:
import * as x from "@actions/github"
  1. tsc

Result:

node_modules/@actions/github/lib/github.d.ts:1:49 - error TS7016: Could not find a declaration file for module '@octokit/graphql'. 'D:/Throwaway/IssuesTest/node_modules/@octokit/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/octokit__graphql` if it exists or add a new declaration (.d.ts) file containing `declare module '@octokit/graphql';`

1 import { GraphQlQueryResponse, Variables } from '@octokit/graphql';
                                                  ~~~~~~~~~~~~~~~~~~

Expected behavior

There shouldn't be errors

Screenshots

Desktop (please complete the following information):

  • OS: I'm on Windows

Additional context

This is a very confusing error because the next logical step for a developer would be to npm install @octokit/graphql, but if you do this, it just changes the error:

node_modules/@actions/github/lib/github.d.ts:1:10 - error TS2305: Module '"../../../../../../Throwaway/IssuesTest/node_modules/@octokit/graphql/dist-types"' has no exported member 'GraphQlQueryResponse'.

1 import { GraphQlQueryResponse, Variables } from '@octokit/graphql';
           ~~~~~~~~~~~~~~~~~~~~

node_modules/@actions/github/lib/github.d.ts:1:32 - error TS2305: Module '"../../../../../../Throwaway/IssuesTest/node_modules/@octokit/graphql/dist-types"' has no exported member 'Variables'.

1 import { GraphQlQueryResponse, Variables } from '@octokit/graphql';
                                 ~~~~~~~~~

It wasn't clear to me why the .ts file loads the checked-in .d.ts instead of just pulling in the real @octokit/grapqhl module? This pattern is guaranteed to break for .d.ts emit unless some other source of type data provides a definition for the module.

Two possible fixes:

Either way the import needs to be updated

@RyanCavanaugh RyanCavanaugh added the bug Something isn't working label Oct 31, 2019
@RyanCavanaugh
Copy link
Author

Digging in a bit deeper while looking into a fix. The .d.ts checked in to this repo for @octokit/graphql describes the 2.0.1 shape (a top-level item named defaults); this shape no longer exists at latest (4.3.0). But 2.0.1 doesn't provide a .d.ts file, so installing that doesn't really help.

@Skycoder42
Copy link

Is there a workaround for this issue until it was fixed?

@johanneslumpe
Copy link

johanneslumpe commented Nov 20, 2019

@Skycoder42 You can put a .d.ts file into a local @types folder which contains this snippet:

declare module '@octokit/graphql' {
  export type Variables = any
  export type GraphQlQueryResponse = any
}

It seems that these are the only used exports and while this does basically disable type-checking for that part of the code, it will allow your action to properly compile.

@thboop thboop removed their assignment Nov 21, 2019
@thboop
Copy link
Collaborator

thboop commented Nov 21, 2019

@hross FYI, you were going to take a look at this

@hross
Copy link
Contributor

hross commented Nov 26, 2019

The other option is to turn off noImplicitAny

@johanneslumpe
Copy link

@hross that should probably be the last thing to try to fix something :)

oke-py added a commit to oke-py/npm-audit-action that referenced this issue Dec 8, 2019
oke-py added a commit to oke-py/npm-audit-action that referenced this issue Dec 8, 2019
* Get GitHub access token from input

* install npm package

* fix TypeScript error to successfully build

ref: actions/toolkit#199

* npm i strip-ansi to remove control characters

* create an issue

* use template literal to pass lint

* npm run format; npm run lint

* use inputs.issue_title as issue title

* document inputs.issue_title

* add inputs.issue_title
@hross
Copy link
Contributor

hross commented Dec 9, 2019

Fixed in #228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants