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
in the useEffect function, the value variable is of type T (because query function returns a Promise<T>) but the setResult function refuses to accept T type. This is because the setResult type is : StateUpdater<T extends (...args: any[]) => infer S ? S : T>
But as P is generic, typescript cannot determine if is a function (and so use the infer type) or not.
May be I'm wrong somewhere ?
btw, this kind of code has not problem with the react hook (it does not try to determine if the generic type pass to useState is a function or not)
Thks for help
Anthony.
The text was updated successfully, but these errors were encountered:
Hello,
I'm trying to code a generic hooks, but the type returns by useState cause a problem.
A simple example :
in the useEffect function, the
value
variable is of type T (becausequery
function returns aPromise<T>
) but the setResult function refuses to accept T type. This is because the setResult type is :StateUpdater<T extends (...args: any[]) => infer S ? S : T>
But as P is generic, typescript cannot determine if is a function (and so use the infer type) or not.
May be I'm wrong somewhere ?
btw, this kind of code has not problem with the react hook (it does not try to determine if the generic type pass to useState is a function or not)
Thks for help
Anthony.
The text was updated successfully, but these errors were encountered: