hooks: useUpdate onError signature typescript issue
See original GitHub issueSince the v4 upgrade of react-admin, I have the following typing issue on the useUpdate
function when I try to access the error.message
property of the parameter provided by the onError
function:
TS2571: Object is of type 'unknown'.
23 | {
24 | onError: (error) => {
> 25 | notify(`Error while updating: ${error.message}`);
| ^^^^^
26 | }
27 | }
28 | )
I also try to specify the type of the error like that: (error: Error) => ...
, but this leads to the following another error:
TS2322: Type '(error: Error) => void' is not assignable to type '(error: unknown, variables: Partial<UseUpdateMutateParams<RaRecord>>, context: unknown) => void | Promise<unknown>'.
Types of parameters 'error' and 'error' are incompatible.
Type 'unknown' is not assignable to type 'Error'.
22 | },
23 | {
> 24 | onError: (error: Error) => {
| ^^^^^^^
25 | notify(`Error while updating: ${error.message}`);
26 | }
27 | }
Steps to reproduce:
- Clone the referenced PR below
- Run
npm start
Related code:
Sandbox PR: https://github.com/soullivaneuh/react-admin-sandbox/pull/1
Other information:
Environment
- React-admin version: v4.0.3
- Last version that did not exhibit the issue (if applicable): v3
- React version: v18
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
[TypeScript] Fix cannot specify the error type in mutation hooks by ...
Provides a way to set the expected type of the error instance that will be propagated to the related functions. closes #7653.
Read more >How to solve customHooks call signature error in react with ...
My question is I would like to use the custom hooks (useCardContext) without the error. How I can solve this issue? reactjs ·...
Read more >React-admin - Querying the API - Marmelab
Querying the API. React-admin provides special hooks to emit read and write queries to the dataProvider , which in turn sends requests to...
Read more >Hooks - Apollo GraphQL Docs
A callback function that's called when your query successfully completes with zero errors (or if errorPolicy is ignore and partial data is returned)....
Read more >react-admin - Projects | FOSSA
License scan found 10 issues. Last scanned 4 hours ago. Found dependencies 15 levels deep. 1665 dependencies · 88 licenses · 11 obligations ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@slax57 I found a way to resolve the issue: https://github.com/marmelab/react-admin/pull/7698
Would you mind take a look? 😃
@slax57 Well… 🙃
Next time I’ll re-read my copy/paste, thanks! 😉
My setup:
Works! However, this double ternary shows indeed the need of a stronger typing to be provided by
useUpdate
.