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:
npm init -ytsc --inita.ts:import * as x from "@actions/github"
tscResult:
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):
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:
@octokit/graphql definition @actions/github -> @octokit/graphqlEither way the import needs to be updated
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.
Is there a workaround for this issue until it was fixed?
@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.
@hross FYI, you were going to take a look at this
The other option is to turn off noImplicitAny
@hross that should probably be the last thing to try to fix something :)
Fixed in #228
Most helpful comment
@Skycoder42 You can put a
.d.tsfile into a local@typesfolder which contains this snippet: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.