Skip to content

InitialFormValues dosen't bridge to FormApi #997

Open
@8823-scholar

Description

@8823-scholar

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

type Data = {
  user: {
    name: string;
    email: string;
  };
};

type RecursivePartial<T> = {
  [P in keyof T]?: T[P] extends (infer U)[]
    ? RecursivePartial<U>[]
    : T[P] extends object
    ? RecursivePartial<T[P]>
    : T[P];
};

<Form<Data, RecursivePartial<Data>> onSubmit={onSubmit}>
    {({ handleSubmit, form }) => {
      useEffect(() => {
        form.initialize({
          user: {
            name: "aaa"
          }
        });
      }, [form]);
      return (
        <form onSubmit={handleSubmit}>
          <Field name="user.name" component="input" />
          <Field name="user.email" component="input" />
        </form>
      );
    }}
  </Form>

form.initialize values type is Partial<Data>.

What is the expected behavior?

form.initialize values type should be RecursivePartial<Data>.

Sandbox Link

https://codesandbox.io/s/laughing-sound-fk5rz4?file=/src/Form.tsx

What's your environment?

    "final-form": "4.20.7",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-final-form": "6.5.9",

Other information

nothing.

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