I need a save button that is visually so different from the normal one, that I opted to build my own based on the SaveButton source code (as suggested in [1]).
However, just an import of the component cause the handleSubmitWithRedirect prop to protest that handleSubmit (I'm also going the customized form road, so handleSubmit here comes from the render property of react-final-form's Form component.) does not match the typing of handleSubmitWithRedirect. This is not a problem when using the SaveButton from the library (although according to WebStorm hswr has no type on SaveButton).
Since handleSubmit works when used with SaveButton.handleSubmitWithRedirect, I assume that there may not be an actual incompatability, just an issue with the type specifications.
I would appreciate help on both how to fix this issue, and/or help to understand exactly what is the issue. I'm quite far from being anywhere good at typescript.
I have tried with typescript 3.6.4 and 3.9.2.
Here is the typescript compiler error:
TS2322: Type '(event?: Partial, "preventDefault" | "stopPropagation">> | undefined) => Promise | undefined' is not assignable to type '(redirect?: string | boolean | RedirectToFunction | undefined) => void'. Types of parameters 'event' and 'redirect' are incompatible. Type 'string | boolean | RedirectToFunction | undefined' is not assignable to type 'Partial, "preventDefault" | "stopPropagation">> | undefined'. Type 'string' is not assignable to type 'Partial, "preventDefault" | "stopPropagation">> | undefined'.
handleSubmit has the type:
(event?: (Partial, "preventDefault" | "stopPropagation">> | undefined)) => (Promise | undefined)
handleSubmitWithRedirect (when SaveButton is imported into my tree) has the type:
((redirect?: (string | boolean | RedirectToFunction | undefined)) => void) | undefined
I ignored this for a while, but I did a react-admin update today, the latest version now being 3.9.5, and checked the SaveButton. Turned out that handleSubmitWithRedirect had had its type amended to
handleSubmitWithRedirect?:
| HandleSubmitWithRedirect
| FormRenderProps['handleSubmit'];
This allowed the suggested assignment of handleSubmit to work also from a TypeScript perspective.