Skip to content

Conversation

@henrikra
Copy link
Contributor

Description

This PR https://github.com/software-mansion/react-native-gesture-handler/pull/1844/files#diff-b55cdbef4907b7045f32cc5360d48d262cca5f94062e353089f189f4460039e0 added node to the types array of tsconfig. This causes all of the React Native projects with gesture-handler as dependency to get Node typings to their project and node has conflicting types with Dom on setTimeout.

This PR gets rid of the node typing and adds a new file which adds missing types to gesture handler project.

Long story short:
🔴 We were requiring the whole NodeJS types just because we wanted to use process.env.JEST_WORKER_ID
✅ Fixed by not requiring NodeJS types and just typed out the process.env.JEST_WORKER_ID

Fixes #1958

Test plan

Run yarn ts-check and see that not TSC errors are produced.

@henrikra henrikra changed the title Fix TypeScript typing issues with setTimeout by removing NodeJS types 🔧🇫🇮 Fix TypeScript typing issues with setTimeout by removing NodeJS types Mar 28, 2022
Copy link
Member

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for taking the time to look into this, however In my opinion a simple ts-ignore with an explanation here instead of adding a new file would suffice in this case. Especially because this way the explanation would be in the same place as the usage.

@henrikra
Copy link
Contributor Author

@j-piasecki Done 🇫🇮 🥑

src/utils.ts Outdated
}

export function isJestEnv(): boolean {
// @ts-ignore Do not use `@types/node` because it will break setTimeout function types in React Native projects

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @henrikra,
Thanks for doing this! 🙌
As it's not only breaking the setTimeout but also other stuff like setInterval, I would rewrite this comment in this way:

Using `@types/node` will prioritise node types over RN types which can break the types in React Native projects.

@j-piasecki j-piasecki merged commit 6687481 into software-mansion:main Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type 'Timeout' is not assignable to type 'number'

3 participants