Skip to content

Possibly wrong submit typescript type #368

Description

@akozhemiakin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions