Type declaration error with useInterval hook's clearInterval function
SirZach opened this issue · comments
Describe the bug
useInterval
is typed as
declare const useInterval: <TCallback extends GenericFunction>(fn: TCallback, milliseconds: number, options?: UseIntervalOptions) => (boolean | (() => void))[];
which means when you do
const [isCleared, clearInterval] = useInterval(() => { }, 1000)
clearInterval
cannot be called as a function since TS thinks it's either a boolean or a function.
To Reproduce
Steps to reproduce the behavior:
Just follow the description with version 3.12.2
Expected behavior
useInterval
should return [boolean, () => void]
as the type
Hey Zach, thanks for taking the time to report this and for being a user of the library 😊
You're totally right, that issue you spotted is incorrect and it definitely needs to be fixed.
I've got a re-factoring of the TypeScript types and some better documentation in the works.
Unfortunately, I can't give you an exact release date just yet... but it's on its way!
In the meantime, if you feel up to it, open a pull request
Should be a quick and easy fix and you'll get some good karma points 😊
Thanks again for your support
Hey can try to fix it?
Hey can try to fix it?
you're more than welcome
Hey @SirZach I have found the file, can you guide me into solving ?
@shyamtawli
you just need to type the result of the useInterval
hook.
Something like:
return [isCleared, clear] as [boolean, () => void]
the same problem is probably affecting useTimeout
as well
Thanks @antonioru for helping me. I have completed what you mentioned above for both useInterval and useTimeout.
That's it ? Should I open a PR.
yes, just run the tests and build the app to make sure everything works.
If so, feel free to open the PR
🎉 This issue has been resolved in version 4.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
@shyamtawli well done!
Thanks for helping me @antonioru
Can you share your twitter handle?