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
Try looking at some of their examples they use void on functions that return nothing I think
like
void signIn()
for example
@Sofianefor 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
i understood the error but it is not supposed to happend since my onSubmit returns void
care to show your code for the
onSubmit
handleSubmit
?you might wanna try restarting TS server and ESlint server
sorry, for
handleSubmit
the handleSubmit comes from the useForm() of react-hook-forms
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 promiseso what's the solution to avoid this error ?
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 fileThe answer is here: https://github.com/orgs/react-hook-form/discussions/8622#discussioncomment-4060570
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? ...