Skip to content

Commit ca31ede

Browse files
authored
fix(react-form): allow interfaces to be assigned to withFieldGroup's props (#1816)
1 parent e401603 commit ca31ede

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

.changeset/cruel-clocks-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/react-form': patch
3+
---
4+
5+
Allow interfaces to be assigned to `withFieldGroup`'s `props`.

packages/react-form/src/createFormHook.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export interface WithFieldGroupProps<
249249
TFieldComponents extends Record<string, ComponentType<any>>,
250250
TFormComponents extends Record<string, ComponentType<any>>,
251251
TSubmitMeta,
252-
TRenderProps extends Record<string, unknown> = Record<string, never>,
252+
TRenderProps extends object = Record<string, never>,
253253
> extends BaseFormOptions<TFieldGroupData, TSubmitMeta> {
254254
// Optional, but adds props to the `render` function outside of `form`
255255
props?: TRenderProps
@@ -445,7 +445,7 @@ export function createFormHook<
445445
function withFieldGroup<
446446
TFieldGroupData,
447447
TSubmitMeta,
448-
TRenderProps extends Record<string, unknown> = {},
448+
TRenderProps extends object = {},
449449
>({
450450
render,
451451
props,

packages/react-form/tests/createFormHook.test-d.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ describe('createFormHook', () => {
820820
const Component5 = <FieldGroup form={form} fields="nope2" />
821821
})
822822

823-
it('should allow interfaces without index signatures to be assigned to `props` in withForm', () => {
823+
it('should allow interfaces without index signatures to be assigned to `props` in withForm and withFormGroup', () => {
824824
interface TestNoSignature {
825825
title: string
826826
}
@@ -842,20 +842,55 @@ describe('createFormHook', () => {
842842
render: () => <></>,
843843
})
844844

845+
const WithFieldGroupComponent1 = withFieldGroup({
846+
defaultValues: { name: '' },
847+
props: {} as TestNoSignature,
848+
render: () => <></>,
849+
})
850+
851+
const WithFieldGroupComponent2 = withFieldGroup({
852+
defaultValues: { name: '' },
853+
props: {} as TestWithSignature,
854+
render: () => <></>,
855+
})
856+
845857
const appForm = useAppForm({ defaultValues: { name: '' } })
846858

847859
const Component1 = <WithFormComponent1 title="" form={appForm} />
848860
const Component2 = (
849861
<WithFormComponent2 title="" something="else" form={appForm} />
850862
)
863+
864+
const FieldGroupComponent1 = (
865+
<WithFieldGroupComponent1
866+
title=""
867+
form={appForm}
868+
fields={{ name: 'name' }}
869+
/>
870+
)
871+
const FieldGroupComponent2 = (
872+
<WithFieldGroupComponent2
873+
title=""
874+
something="else"
875+
form={appForm}
876+
fields={{ name: 'name' }}
877+
/>
878+
)
851879
})
852880

853-
it('should not allow null as prop in withForm', () => {
881+
it('should not allow null as prop in withForm and withFormGroup', () => {
854882
const WithFormComponent = withForm({
855883
defaultValues: { name: '' },
856884
// @ts-expect-error
857885
props: null,
858886
render: () => <></>,
859887
})
860888
})
889+
890+
const WithFieldGroupComponent = withFieldGroup({
891+
defaultValues: { name: '' },
892+
// @ts-expect-error
893+
props: null,
894+
render: () => <></>,
895+
})
861896
})

0 commit comments

Comments
 (0)