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

Type error in main gatsby package index.d.ts: Type 'Node' is not generic #31324

Closed
timmywil opened this issue May 7, 2021 · 6 comments · Fixed by #31358
Closed

Type error in main gatsby package index.d.ts: Type 'Node' is not generic #31324

timmywil opened this issue May 7, 2021 · 6 comments · Fixed by #31358
Assignees
Labels
topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript type: bug An issue or pull request relating to a bug in Gatsby

Comments

@timmywil
Copy link

timmywil commented May 7, 2021

Description

Not a dupe of #31135

PR #30819 is causing a type error on type checks. This is an issue with gatsby@3.6.0-next.0 and the default branch.

node_modules/gatsby/index.d.ts(746,9): error TS2315: Type 'Node' is not generic.

Specifically, this change where the Node type is treated as generic, but you can see here that it is not.

Steps to reproduce

Run a typescript type checker on packages/gatsby/index.d.ts. I noticed that the typescript checker in this repo only checks files in package src folders. It may be worth adding *.d.ts files as well, at least those in the main gatsby package to avoid errors like this in the future.

Expected result

No type error.

Actual result

node_modules/gatsby/index.d.ts(746,9): error TS2315: Type 'Node' is not generic.

Environment

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  Binaries:
    Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 2.7.15 - C:\Users\4timm\.windows-build-tools\python27\python.EXE
  Browsers:
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.51)
  npmPackages:
    gatsby: ^3.6.0-next.0 => 3.6.0-next.0 
    gatsby-link: ^3.4.0 => 3.4.0 
    gatsby-plugin-canonical-urls: ^3.4.0 => 3.4.0 
    gatsby-plugin-create-client-paths: ^3.4.0 => 3.4.0 
    gatsby-plugin-emotion: ^6.4.0 => 6.4.0 
    gatsby-plugin-feed: ^3.4.0 => 3.4.0 
    gatsby-plugin-google-analytics: ^3.4.0 => 3.4.0 
    gatsby-plugin-google-tagmanager: ^3.4.0 => 3.4.0 
    gatsby-plugin-image: ^1.4.0 => 1.4.0 
    gatsby-plugin-manifest: ^3.4.0 => 3.4.0 
    gatsby-plugin-offline: ^4.4.0 => 4.4.0 
    gatsby-plugin-optimize-svgs: ^1.0.5 => 1.0.5 
    gatsby-plugin-react-helmet: ^4.4.0 => 4.4.0 
    gatsby-plugin-react-svg: ^3.0.1 => 3.0.1 
    gatsby-plugin-remove-trailing-slashes: ^3.4.0 => 3.4.0 
    gatsby-plugin-s3: ^0.3.8 => 0.3.8 
    gatsby-plugin-sharp: ^3.4.1 => 3.4.1 
    gatsby-plugin-sitemap: ^4.0.0 => 4.0.0 
    gatsby-plugin-twitter: ^3.4.0 => 3.4.0 
    gatsby-plugin-typescript: ^3.4.0 => 3.4.0 
    gatsby-plugin-web-font-loader: ^1.0.4 => 1.0.4 
    gatsby-react-router-scroll: ^4.4.0 => 4.4.0 
    gatsby-remark-autolink-headers: ^4.1.0 => 4.1.0 
    gatsby-remark-check-links: ^2.1.0 => 2.1.0 
    gatsby-remark-copy-linked-files: ^4.1.0 => 4.1.0 
    gatsby-remark-embed-video: ^3.1.1 => 3.1.1 
    gatsby-remark-embedder: ^5.0.0 => 5.0.0 
    gatsby-remark-find-replace: ^0.3.0 => 0.3.0 
    gatsby-remark-images: ^5.1.0 => 5.1.0 
    gatsby-remark-prismjs: ^5.1.0 => 5.1.0 
    gatsby-remark-responsive-iframe: ^4.1.0 => 4.1.0 
    gatsby-remark-smartypants: ^4.1.0 => 4.1.0 
    gatsby-source-filesystem: ^3.4.0 => 3.4.0 
    gatsby-source-graphql: ^3.4.0 => 3.4.0 
    gatsby-transformer-remark: ^4.1.0 => 4.1.0 
    gatsby-transformer-sharp: ^3.4.0 => 3.4.0 
@timmywil timmywil added the type: bug An issue or pull request relating to a bug in Gatsby label May 7, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 7, 2021
@vladar vladar added topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 7, 2021
@vladar
Copy link
Contributor

vladar commented May 7, 2021

Makes sense to me 👍 Are you interested in putting up a PR with this change? We will gratefully merge it (make sure to tag me in the PR if you are up to it).

@timmywil
Copy link
Author

timmywil commented May 7, 2021

I can do that. I assume that line would just return to an intersection: Node & TNode, rather than making the Node type generic?

@LekoArts
Copy link
Contributor

Yeah, Node & TNode would be better! This was also done here: aa09e6f#diff-15724d4352562f842e4eb9df3a864711b1617ea4ebabc56c2aee4e975bca6767R1087

@LekoArts LekoArts self-assigned this May 11, 2021
@LekoArts
Copy link
Contributor

I'll get it fixed before the stable release

@LekoArts
Copy link
Contributor

So unfortunately we won't be able to immediately run our type checking on *.d.ts files in gatsby as we're blocked by this feature request: microsoft/TypeScript#30511

The https://github.com/gatsbyjs/gatsby/blob/master/scripts/check-ts.js file picks up directories that have .ts files or a tsconfig (which gatsby has) and adds the directory to the -p flag.

Then the existing tsconfig.json decides what to do: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/tsconfig.json

Since we have skipLibCheck in our root tsconfig this file needs to add skipLibCheck: false. However, @types/webpack v4 seems to mess up this:

image

So while it shows the incorrect type it also has too much other stuff in there.
For now I'll just fix the error and then see in a follow-up PR if maybe the types can be fixed with yarn resolutions.

@timmywil
Copy link
Author

timmywil commented May 11, 2021

Thanks, sorry I didn't get to it. Regarding the skipLibCheck issue, check-ts could probably run a distinct sanity check on *.d.ts* without -p in a separate typescript run, but I understand if you want to wait until you can run them all together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants