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 @types/graceful-fs a dev dependency #10463

Conversation

newyankeecodeshop
Copy link

Summary

When upgrading our project to React Native 0.63, we upgraded Jest from 24.7 to 25.5, as specified by the React Native upgrade helper. After doing this, when type-checking our app with TypeScript 3.7, we got errors from global APIs like setInterval. It turns out Typescript was type-checking the timeout APIs using @types/node. This dependency was brought in via jest-haste-map@25.5.1, via @types/graceful-fs.

From our yarn.lock file:

jest-haste-map@^25.5.1:
  version "25.5.1"
  resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-25.5.1.tgz#1df10f716c1d94e60a1ebf7798c9fb3da2620943"
  integrity sha512-dddgh9UZjV7SCDQUrQ+5t9yy8iEgKc1AKqZR9YDww8xsVOtzPQSMVLDChc21+g29oTRexb9/B0bIlZL+sWmvAQ==
  dependencies:
    "@jest/types" "^25.5.0"
    "@types/graceful-fs" "^4.1.2"
    anymatch "^3.0.3"
    fb-watchman "^2.0.0"
    graceful-fs "^4.2.4"
    jest-serializer "^25.5.0"
    jest-util "^25.5.0"
    jest-worker "^25.5.0"
    micromatch "^4.0.2"
    sane "^4.0.3"
    walker "^1.0.7"
    which "^2.0.2"
  optionalDependencies:
    fsevents "^2.1.2"

Including @types/node in a React Native TypeScript application causes type collisions with global APIs such as setTimeout and setInterval.

Other jest packages, such as jest-config, do not include "@types/" dependencies.

Test plan

Running yarn build does not show any errors related to @types/graceful-fs.

@merceyz
Copy link
Contributor

merceyz commented Aug 31, 2020

It was added in #9913 to fix microsoft/playwright-test#38.

jest-haste-map depends on those types so it must be declared, the fix on your side is to update your tsconfig.json to not include all @types packages automatically https://www.typescriptlang.org/tsconfig#types

turns out Typescript was type-checking the timeout APIs using @types/node. This dependency was brought in via jest-haste-map@25.5.1, via @types/graceful-fs.

More likely it's brought in by https://github.com/facebook/jest/blob/6f7db3e40f88678f4986c969c6a76c575b51a138/packages/jest-haste-map/package.json#L15

@newyankeecodeshop
Copy link
Author

Ok thank you. I guess this will be an ongoing tension between React Native and Node as more libraries use TypeScript.

@newyankeecodeshop newyankeecodeshop deleted the fix-types-dependency branch August 31, 2020 16:30
@SimenB
Copy link
Member

SimenB commented Aug 31, 2020

Yeah, globals are hard to deal with across environments unfortunately 🙁

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants