Skip to content

Commit

Permalink
Merge pull request #318 from Alex-Yakubovsky/use-deep-partial-for-val…
Browse files Browse the repository at this point in the history
…idated-form-data-type

use `DeepPartial` for acceptable `DataType` into `ValidatedForm`
  • Loading branch information
airjp73 committed Aug 14, 2023
2 parents b294bff + 9b02b05 commit acee27f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/remix-validated-form/src/ValidatedForm.tsx
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

1 comment on commit acee27f

@vercel
Copy link

@vercel vercel bot commented on acee27f Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.