Eslint bug or am I missing something ?

Please can someone tell me why am i getting this error : even though my function is equal to : const onSubmit = (data: IQuestion) => console.log(data);
11 Replies
outis99
outis992y ago
Try looking at some of their examples they use void on functions that return nothing I think like void signIn() for example @Sofiane
caxco93
caxco932y ago
for what I can see it says your call to handleSubmit returns a function that returns a promise. That function that returns a promise is being passed to onSubmit, but onSubmit is expecting a function that returns void it's an eslint rule set up on your project though if you check the second line it says it's the rule called @typescript-eslint/no-misused-promises https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-misused-promises.md
detects code that provides Promises to incorrect logical locations
Sofiane
SofianeOP2y ago
i understood the error but it is not supposed to happend since my onSubmit returns void
caxco93
caxco932y ago
care to show your code for the onSubmit handleSubmit?
Sofiane
SofianeOP2y ago
caxco93
caxco932y ago
you might wanna try restarting TS server and ESlint server sorry, for handleSubmit
Sofiane
SofianeOP2y ago
the handleSubmit comes from the useForm() of react-hook-forms
caxco93
caxco932y ago
when you write handleSubmit(onSubmit) , you are indeed calling handleSubmit and passing onSubmit as an argument it is the executed return value of handleSubmit that is being passed to the form's onSubmit prop handleSubmit infact returns a function that returns a promise
Sofiane
SofianeOP2y ago
so what's the solution to avoid this error ?
caxco93
caxco932y ago
first of all you should make sure you really want a function that returns a promise in your form's onSubmit. although apparently that's the way it is intended with react-hook-forms. You should also know why do you have the @typescript-eslint/no-misused-promises rule? is this eslint configuration provided by a project you are contributing to? is it an eslint config you are basing yours on (is it only your project)? depending on these info you can then simply add a line ignore or even disable it completely on your .eslintrc file
Sofiane
SofianeOP2y ago
GitHub
Promise-returning function provided to attribute where a void retur...
I am having a typescript-eslint error checked this one which is also recommended on react-hook-form website, following the same. We are using next:12.1.0 react-hook-form:7.24.0 how can I solve it? ...
Want results from more Discord servers?
Add your server