final-form / final-form

🏁 Framework agnostic, high performance, subscription-based form state management

Home Page:https://final-form.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibly wrong submit typescript type

akozhemiakin opened this issue · comments

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