final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 479 forks source link

Possibly wrong submit typescript type #835

Closed akozhemiakin closed 4 years ago

akozhemiakin commented 4 years ago

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

Currently we have the following FormApi type:

export interface FormApi<FormValues = Record<string, any>, InitialFormValues = Partial<FormValues>> {
    submit: () => Promise<FormValues | undefined> | undefined
    ...
}

What is the expected behavior?

In documentation it is stated that it should return some arbitrary object

Submits the form if there are currently no validation errors. It may return undefined or a Promise depending on the nature of the onSubmit configuration value given to the form when it was created.

() => Promise<?Object> | void

And in react-final-form docs it is stated that submit callback (its promise returning variant):

Returns a Promise<?Object> that resolves with no value on success or resolves with an Object of submission errors on failure. The reason it resolves with errors is to leave rejection for when there is a server or communications error.

I believe that submit callback is not constrained by returning the result of type FormValues | undefined.

Should not it be typed like this?

submit: () => Promise<SubmissionErrors | undefined> | undefined
akozhemiakin commented 4 years ago

Sorry, should have filed this issue to final-form tracker, not react-final-form one