react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

InitialFormValues dosen't bridge to FormApi

Open 8823-scholar opened this issue 3 years ago • 0 comments

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.

8823-scholar avatar Jun 28 '22 18:06 8823-scholar