diff --git a/docs/framework/react/guides/reusable-fields.md b/docs/framework/react/guides/reusable-fields.md index 6541f37a3..c1489223f 100644 --- a/docs/framework/react/guides/reusable-fields.md +++ b/docs/framework/react/guides/reusable-fields.md @@ -18,7 +18,7 @@ export default function GenericTextField< TFormValidator extends Validator | undefined, >({ name, form }: { name: TName; - form: ReturnType + form: UseFormReturnType, > }): JSX.Element { return ( @@ -62,11 +62,11 @@ import { useForm, Validator, InferValidFormKeys } from '@tanstack/react-form'; export default function GenericTextField< TForm, + TFormValidator TName extends InferValidFormKeys, - TFormValidator extends Validator | undefined, >({ name, form }: { name: TName; - form: ReturnType + form: UseFormReturnType > }): JSX.Element { return ( diff --git a/packages/react-form/src/types.ts b/packages/react-form/src/types.ts index 8f39d95cb..790378120 100644 --- a/packages/react-form/src/types.ts +++ b/packages/react-form/src/types.ts @@ -5,6 +5,7 @@ import type { Validator, } from '@tanstack/form-core' import type { FunctionComponent } from 'react' +import { useForm } from './useForm' /** * The field options. @@ -28,3 +29,12 @@ export type UseFieldOptions< > & { mode?: 'value' | 'array' } + +/** + * The return type use useForm with pre-populated generics + */ +export type UseFormReturnType = TFormValidator extends + | Validator + | undefined + ? ReturnType> + : never