Skip to content

Commit b313b8a

Browse files
authored
fix(react-form): Allow interfaces to be assigned to withForm's props (#1601)
fix(react-form): Allow interfaces to be used for withForm props
1 parent e669d93 commit b313b8a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

packages/react-form/src/createFormHook.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export interface WithFormProps<
183183
TSubmitMeta,
184184
TFieldComponents extends Record<string, ComponentType<any>>,
185185
TFormComponents extends Record<string, ComponentType<any>>,
186-
TRenderProps extends Record<string, unknown> = Record<string, never>,
186+
TRenderProps extends object = Record<string, never>,
187187
> extends FormOptions<
188188
TFormData,
189189
TOnMount,
@@ -326,7 +326,7 @@ export function createFormHook<
326326
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
327327
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
328328
TSubmitMeta,
329-
TRenderProps extends Record<string, unknown> = {},
329+
TRenderProps extends object = {},
330330
>({
331331
render,
332332
props,

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,43 @@ describe('createFormHook', () => {
249249
<WithFormComponent form={incorrectAppForm} prop1="test" prop2={10} />
250250
)
251251
})
252+
253+
it('should allow interfaces without index signatures to be assigned to `props` in withForm', () => {
254+
interface TestNoSignature {
255+
title: string
256+
}
257+
258+
interface TestWithSignature {
259+
title: string
260+
[key: string]: unknown
261+
}
262+
263+
const WithFormComponent1 = withForm({
264+
defaultValues: { name: '' },
265+
props: {} as TestNoSignature,
266+
render: () => <></>,
267+
})
268+
269+
const WithFormComponent2 = withForm({
270+
defaultValues: { name: '' },
271+
props: {} as TestWithSignature,
272+
render: () => <></>,
273+
})
274+
275+
const appForm = useAppForm({ defaultValues: { name: '' } })
276+
277+
const Component1 = <WithFormComponent1 title="" form={appForm} />
278+
const Component2 = (
279+
<WithFormComponent2 title="" something="else" form={appForm} />
280+
)
281+
})
282+
283+
it('should not allow null as prop in withForm', () => {
284+
const WithFormComponent = withForm({
285+
defaultValues: { name: '' },
286+
// @ts-expect-error
287+
props: null,
288+
render: () => <></>,
289+
})
290+
})
252291
})

0 commit comments

Comments
 (0)