question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Description

After upgrading to the latest version, all the setTimeouts and SetIntervals types are broken. It turned out that somehow RN-Gesture-Handler picks the Node types as default instead of the RN types. Also, these are related to this issue:

Platforms

  • iOS
  • Android
  • Web

Screenshots

Screenshot 2022-03-28 at 11 55 41

Steps To Reproduce

  1. Clone the latest version
  2. install node_modules for both root directory and the example project
  3. Add this snippet to the App.tsx
  const myTimer = React.useRef(0);

  React.useEffect(() => {
    myTimer.current = setTimeout(() => {
      console.log('Hello');
    }, 1000);
  }, []);
  1. You will get this error:
Type 'Timeout' is not assignable to type 'number'
  1. Go to root directory and open the tsconfig.json
  2. Change the types value from ["node", "jest"] to []
  3. The error will disappear

Expected behavior

It should respect RN types

Actual behavior

It uses node types

Snack or minimal code example

Package versions

  • React: 17.0.2
  • React Native: 0.65.2
  • React Native Gesture Handler: 2.3.2
  • React Native Reanimated: 2.4.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hamidhadicommented, May 18, 2022

You are right. Sorry for the confusion. Yes, I got the same result on the fresh app, which wasn’t the case when I created this issue. I’ll continue following up on this in the RN repo. 👍

1reaction
j-piaseckicommented, Apr 20, 2022

Hi @hamidhadi, Are you sure it’s because of Gesture Handler 😅 ? I’m asking because I just tried, and I got this error on a fresh RN 0.68 app without installing any additional libraries (it went away after I added "types": [] to tsconfig.json), while it’s fine in the Example app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"TS2322: Type 'Timeout' is not assignable to type 'number ...
The solution I came up with is timeOut = setTimeout(...) as unknown as number; Thereby trying to tell the compiler that setTimeout indeed ......
Read more >
Type 'number' is not assignable to type 'Timeout' · Issue #30128
NodeJS.Timeout is a more general type than number . To work around any type issues here when working purely in node and not...
Read more >
React Native fixing typescript issue: "Type 'Timeout' is not ...
React Native fixing typescript issue: "Type 'Timeout' is not assignable to type 'number'" The primary issue is that @type/node global types ...
Read more >
Type 'Timeout' is not assignable to type 'number'.
Contents. Code Examples. Type 'Timeout' is not assignable to type 'number'. Related Problems.
Read more >
Microsoft/TypeScript - Gitter
I have setTimeout(() => { /*some code in here*/ }, 300); But I'm getting : error TS2322: Type 'Timer' is not assignable to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found