Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use DeepPartial for acceptable DataType into ValidatedForm #318

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/remix-validated-form/src/ValidatedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ import {
} from "./internal/util";
import { FieldErrors, Validator } from "./validation/types";

type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;

type SubactionData<
DataType,
Subaction extends string | undefined
Expand Down Expand Up @@ -83,7 +89,7 @@ export type FormProps<DataType, Subaction extends string | undefined> = {
* Accepts an object of default values for the form
* that will automatically be propagated to the form fields via `useField`.
*/
defaultValues?: Partial<DataForSubaction<DataType, Subaction>>;
defaultValues?: DeepPartial<DataForSubaction<DataType, Subaction>>;
/**
* A ref to the form element.
*/
Expand Down Expand Up @@ -221,7 +227,10 @@ type HTMLFormSubmitter = HTMLButtonElement | HTMLInputElement;
/**
* The primary form component of `remix-validated-form`.
*/
export function ValidatedForm<DataType, Subaction extends string | undefined>({
export function ValidatedForm<
DataType extends { [fieldName: string]: any },
Subaction extends string | undefined
>({
validator,
onSubmit,
children,
Expand Down
Loading