Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions packages/conform-react/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ export type Metadata<
dirty: boolean;
};

export type FieldsetMetadata<
Schema extends Record<string, unknown> = Record<string, unknown>,
FormError = string[],
> = Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<
Combine<Schema>[Key],
Schema,
FormError
>;
}>;

Comment on lines +63 to +73
Copy link
Owner

Choose a reason for hiding this comment

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

We should reuse this for the return type of getFieldset() on SubfieldMetadata well. Meaning Schema and FormSchema could be different. Maybe something like this?

export type FieldsetMetadata<
	Schema extends Record<string, unknown> = Record<string, unknown>,
	FormSchema extends Record<string, any> = Schema,
	FormError = string[],
> = Required<{
	[Key in keyof Combine<Schema>]: FieldMetadata<
		Combine<Schema>[Key],
		FormSchema,
		FormError
	>;
}>;

export type FormMetadata<
Schema extends Record<string, unknown> = Record<string, unknown>,
FormError = string[],
Expand All @@ -68,13 +79,7 @@ export type FormMetadata<
id: FormId<Schema, FormError>;
context: Wrapped<FormContext<Schema, FormError>>;
status?: 'success' | 'error';
getFieldset: () => Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<
Combine<Schema>[Key],
Schema,
FormError
>;
}>;
getFieldset: () => FieldsetMetadata<Schema, FormError>;
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
noValidate: boolean;
};
Expand Down
1 change: 1 addition & 0 deletions packages/conform-react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
} from '@conform-to/dom';
export {
type FieldMetadata,
type FieldsetMetadata,
type FormMetadata,
FormProvider,
FormStateInput,
Expand Down
Loading