You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
renderHook (and rerender) doesn't properly infer overload type when using initialProps. #822
I have a react hook, that relies on overloading to solve different use-cases. Essentially, this hook has an overload that determines the appropriate way to resolve a value based on its parameter typeof.
What happened:
When faced with an overloadable hook, @react-testing-library/react-hooks isn't appropriately typing either the initialProps for the renderHook method, or the rerender method itself.
Hook overloading only works when you explicitly call the hook and return it's value on the renderHook method, while when using the renderHook with the initialValue option, it doesn't properly generate the types to match the overload.
Activity
rnarcos commentedon Apr 11, 2022
Also, render result does not update its type definition based on the
rerenderoutput.alishi973 commentedon Sep 19, 2023
We faced this issue even on the latest version (8.0.1), any idea?
emericspiroux commentedon Oct 20, 2023
Salutations !
I think you doesn't use
renderHookwell.You need to do this :
This solution work for me 👍
I think renderHook is not well designed to easily understand it and can be a good thing if in the future it can work like that :
mpeyper commentedon Dec 19, 2023
Sorry I'm a bit late to the party here. I believe this is a known limitation of generic type inference of overloaded functions in Typescript.