Type 'Timeout' is not assignable to type 'number'
See original GitHub issueDescription
After upgrading to the latest version, all the setTimeout
s and SetInterval
s 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:
-
https://github.com/software-mansion/react-native-gesture-handler/pull/1420
-
https://github.com/software-mansion/react-native-gesture-handler/issues/1384
Platforms
- iOS
- Android
- Web
Screenshots
Steps To Reproduce
- Clone the latest version
- install
node_modules
for both root directory and the example project - Add this snippet to the
App.tsx
const myTimer = React.useRef(0);
React.useEffect(() => {
myTimer.current = setTimeout(() => {
console.log('Hello');
}, 1000);
}, []);
- You will get this error:
Type 'Timeout' is not assignable to type 'number'
- Go to root directory and open the
tsconfig.json
- Change the types value from
["node", "jest"]
to[]
- 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:
- Created a year ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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. 👍
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": []
totsconfig.json
), while it’s fine in the Example app.