Skip to content

Commit

Permalink
Make modifiedValues typesafe
Browse files Browse the repository at this point in the history
  • Loading branch information
ilbrando committed Jun 28, 2024
1 parent 6b8e7cf commit cd8ad56
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/simple-form/src/get-form-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const getFormManager = <TFields>(formDefinition: ReturnType<typeof useFor
* form manager can be passed on to field controls and they have access to the form state.
*/
formState,
/** This is the `isSubitting` parameter you called this hook with. It is included in the result so the
/** This is the `isSubmitting` parameter you called this hook with. It is included in the result so the
* form manager can be passed on to field controls and they have access to the submitting state.
*/
isSubmitting,
Expand Down
4 changes: 2 additions & 2 deletions packages/simple-form/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export const getFieldValues = <TFields>(formState: FormState<TFields>, fieldName
return values;
};

export const getModifiedFieldValues = <T extends Record<string, unknown>>(initialFieldValues: T, fieldValues: T) => {
export const getModifiedFieldValues = <TFields, T extends MakeNullable<TFields>>(initialFieldValues: T, fieldValues: T) => {
const initialFieldValueEntries = new Map(Object.entries(initialFieldValues));
const fieldValueEntries = Object.entries(fieldValues);
return Object.fromEntries(
fieldValueEntries.filter(([key, value]) => {
const initialValue = initialFieldValueEntries.get(key);
return !isEqual(value, initialValue);
})
);
) as Partial<T>;
};

0 comments on commit cd8ad56

Please sign in to comment.