diff --git a/docs/framework/lit/reference/classes/tanstackformcontroller.md b/docs/framework/lit/reference/classes/tanstackformcontroller.md index 83fe16bb8..30f5e3e7b 100644 --- a/docs/framework/lit/reference/classes/tanstackformcontroller.md +++ b/docs/framework/lit/reference/classes/tanstackformcontroller.md @@ -81,7 +81,7 @@ Defined in: [tanstack-form-controller.ts:259](https://github.com/TanStack/form/b #### Type Parameters -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** diff --git a/docs/framework/react/reference/functions/field.md b/docs/framework/react/reference/functions/field.md index 1f9a8accb..10f67f55a 100644 --- a/docs/framework/react/reference/functions/field.md +++ b/docs/framework/react/reference/functions/field.md @@ -11,7 +11,7 @@ title: Field function Field(__namedParameters): ReactNode ``` -Defined in: [packages/react-form/src/useField.tsx:369](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L369) +Defined in: [packages/react-form/src/useField.tsx:425](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L425) A function component that takes field options and a render function as children and returns a React component. @@ -21,7 +21,7 @@ The `Field` component uses the `useField` hook internally to manage the field in • **TParentData** -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** diff --git a/docs/framework/react/reference/functions/usefield.md b/docs/framework/react/reference/functions/usefield.md index 3129ca3e7..7d26acf7d 100644 --- a/docs/framework/react/reference/functions/usefield.md +++ b/docs/framework/react/reference/functions/usefield.md @@ -11,7 +11,7 @@ title: useField function useField(opts): FieldApi & ReactFieldApi ``` -Defined in: [packages/react-form/src/useField.tsx:130](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L130) +Defined in: [packages/react-form/src/useField.tsx:118](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L118) A hook for managing a field in a form. @@ -19,7 +19,7 @@ A hook for managing a field in a form. • **TParentData** -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** diff --git a/docs/framework/react/reference/type-aliases/fieldcomponent.md b/docs/framework/react/reference/type-aliases/fieldcomponent.md index 940f32542..9e29a8f55 100644 --- a/docs/framework/react/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/react/reference/type-aliases/fieldcomponent.md @@ -14,7 +14,7 @@ type FieldComponent ReactNode; ``` -Defined in: [packages/react-form/src/useField.tsx:307](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L307) +Defined in: [packages/react-form/src/useField.tsx:360](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L360) A type alias representing a field component for a specific form data type. @@ -69,7 +69,7 @@ A type alias representing a field component for a specific form data type. ...fieldOptions \} -`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TPatentSubmitMeta`, `ExtendedApi`\>, `"form"`\> +`FieldComponentBoundProps`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TPatentSubmitMeta`, `ExtendedApi`\> ## Returns diff --git a/docs/framework/react/reference/type-aliases/usefield.md b/docs/framework/react/reference/type-aliases/usefield.md index 3d3226bab..aaebb1fe2 100644 --- a/docs/framework/react/reference/type-aliases/usefield.md +++ b/docs/framework/react/reference/type-aliases/usefield.md @@ -63,7 +63,7 @@ A function that takes an optional object with a `name` property and field option ### opts -`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TPatentSubmitMeta`\>, `"form"`\> +`UseFieldOptionsBound`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`\> ## Returns diff --git a/docs/framework/solid/reference/functions/createfield.md b/docs/framework/solid/reference/functions/createfield.md index 6b6769ef5..55ad9bca4 100644 --- a/docs/framework/solid/reference/functions/createfield.md +++ b/docs/framework/solid/reference/functions/createfield.md @@ -11,13 +11,13 @@ title: createField function createField(opts): () => FieldApi & SolidFieldApi ``` -Defined in: [packages/solid-form/src/createField.tsx:236](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L236) +Defined in: [packages/solid-form/src/createField.tsx:223](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L223) ## Type Parameters • **TParentData** -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** diff --git a/docs/framework/solid/reference/functions/field.md b/docs/framework/solid/reference/functions/field.md index 5c2a3f014..35ccb37a1 100644 --- a/docs/framework/solid/reference/functions/field.md +++ b/docs/framework/solid/reference/functions/field.md @@ -11,13 +11,13 @@ title: Field function Field(props): Element ``` -Defined in: [packages/solid-form/src/createField.tsx:480](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L480) +Defined in: [packages/solid-form/src/createField.tsx:524](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L524) ## Type Parameters • **TParentData** -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** @@ -57,7 +57,7 @@ Defined in: [packages/solid-form/src/createField.tsx:480](https://github.com/Tan ### props -`object` & `FieldApiOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\> & `object` +`FieldComponentProps`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\> ## Returns diff --git a/docs/framework/solid/reference/type-aliases/createfield.md b/docs/framework/solid/reference/type-aliases/createfield.md index bacbe6a84..c45efcc8e 100644 --- a/docs/framework/solid/reference/type-aliases/createfield.md +++ b/docs/framework/solid/reference/type-aliases/createfield.md @@ -8,7 +8,7 @@ title: CreateField # Type Alias: CreateField()\ ```ts -type CreateField = (opts) => () => FieldApi & SolidFieldApi; +type CreateField = (opts) => () => FieldApi & SolidFieldApi; ``` Defined in: [packages/solid-form/src/createField.tsx:49](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L49) @@ -55,13 +55,11 @@ Defined in: [packages/solid-form/src/createField.tsx:49](https://github.com/TanS • **TOnSubmitAsync** *extends* `undefined` \| `FieldAsyncValidateOrFn`\<`TParentData`, `TName`, `TData`\> -• **TSubmitMeta** - ## Parameters ### opts -() => `object` & `Omit`\<`CreateFieldOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TSubmitMeta`\>, `"form"`\> +() => `object` & `CreateFieldOptionsBound`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`\> ## Returns diff --git a/docs/framework/solid/reference/type-aliases/fieldcomponent.md b/docs/framework/solid/reference/type-aliases/fieldcomponent.md index 84aefbf0a..f61dc4803 100644 --- a/docs/framework/solid/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/solid/reference/type-aliases/fieldcomponent.md @@ -14,7 +14,7 @@ type FieldComponent JSXElement; ``` -Defined in: [packages/solid-form/src/createField.tsx:425](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L425) +Defined in: [packages/solid-form/src/createField.tsx:400](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L400) ## Type Parameters @@ -65,7 +65,7 @@ Defined in: [packages/solid-form/src/createField.tsx:425](https://github.com/Tan ...fieldOptions \} -`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>, `"form"`\> +`FieldComponentBoundProps`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\> ## Returns diff --git a/docs/framework/vue/reference/functions/usefield.md b/docs/framework/vue/reference/functions/usefield.md index 7ac8f59fc..f2ddae3d1 100644 --- a/docs/framework/vue/reference/functions/usefield.md +++ b/docs/framework/vue/reference/functions/usefield.md @@ -11,13 +11,13 @@ title: useField function useField(opts): object ``` -Defined in: [packages/vue-form/src/useField.tsx:303](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L303) +Defined in: [packages/vue-form/src/useField.tsx:267](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L267) ## Type Parameters • **TParentData** -• **TName** *extends* `string` \| `number` +• **TName** *extends* `string` • **TData** diff --git a/docs/framework/vue/reference/index.md b/docs/framework/vue/reference/index.md index 0ff69a5aa..ea7b8ad38 100644 --- a/docs/framework/vue/reference/index.md +++ b/docs/framework/vue/reference/index.md @@ -15,6 +15,7 @@ title: "@tanstack/vue-form" ## Type Aliases - [FieldComponent](type-aliases/fieldcomponent.md) +- [FieldComponentBoundProps](type-aliases/fieldcomponentboundprops.md) - [FieldComponentProps](type-aliases/fieldcomponentprops.md) - [UseField](type-aliases/usefield.md) diff --git a/docs/framework/vue/reference/interfaces/vuefieldapi.md b/docs/framework/vue/reference/interfaces/vuefieldapi.md index 7ac8a49fd..6359b1c13 100644 --- a/docs/framework/vue/reference/interfaces/vuefieldapi.md +++ b/docs/framework/vue/reference/interfaces/vuefieldapi.md @@ -7,7 +7,7 @@ title: VueFieldApi # Interface: VueFieldApi\ -Defined in: [packages/vue-form/src/useField.tsx:164](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L164) +Defined in: [packages/vue-form/src/useField.tsx:140](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L140) ## Type Parameters @@ -39,4 +39,4 @@ Defined in: [packages/vue-form/src/useField.tsx:164](https://github.com/TanStack Field: FieldComponent; ``` -Defined in: [packages/vue-form/src/useField.tsx:176](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L176) +Defined in: [packages/vue-form/src/useField.tsx:152](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L152) diff --git a/docs/framework/vue/reference/type-aliases/fieldcomponent.md b/docs/framework/vue/reference/type-aliases/fieldcomponent.md index 9ec7ede80..b2e6c559a 100644 --- a/docs/framework/vue/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/vue/reference/type-aliases/fieldcomponent.md @@ -8,7 +8,7 @@ title: FieldComponent # Type Alias: FieldComponent()\ ```ts -type FieldComponent = (props) => CreateComponentPublicInstanceWithMixins, "form">, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, SlotsType<{ +type FieldComponent = (props) => CreateComponentPublicInstanceWithMixins, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, SlotsType<{ default: { field: FieldApi; state: FieldApi["state"]; @@ -44,11 +44,11 @@ Defined in: [packages/vue-form/src/useField.tsx:24](https://github.com/TanStack/ ### props -`Omit`\<[`FieldComponentProps`](fieldcomponentprops.md)\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>, `"form"`\> & `EmitsToProps`\<`EmitsOptions`\> & `PublicProps` +[`FieldComponentBoundProps`](fieldcomponentboundprops.md)\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`\> & `EmitsToProps`\<`EmitsOptions`\> & `PublicProps` ## Returns -`CreateComponentPublicInstanceWithMixins`\<`Omit`\<[`FieldComponentProps`](fieldcomponentprops.md)\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>, `"form"`\>, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, `SlotsType`\<\{ +`CreateComponentPublicInstanceWithMixins`\<[`FieldComponentBoundProps`](fieldcomponentboundprops.md)\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`\>, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, `SlotsType`\<\{ `default`: \{ `field`: `FieldApi`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>; `state`: `FieldApi`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>\[`"state"`\]; diff --git a/docs/framework/vue/reference/type-aliases/fieldcomponentboundprops.md b/docs/framework/vue/reference/type-aliases/fieldcomponentboundprops.md new file mode 100644 index 000000000..2a01e5c68 --- /dev/null +++ b/docs/framework/vue/reference/type-aliases/fieldcomponentboundprops.md @@ -0,0 +1,36 @@ +--- +id: FieldComponentBoundProps +title: FieldComponentBoundProps +--- + + + +# Type Alias: FieldComponentBoundProps\ + +```ts +type FieldComponentBoundProps = UseFieldOptionsBound; +``` + +Defined in: [packages/vue-form/src/useField.tsx:412](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L412) + +## Type Parameters + +• **TParentData** + +• **TName** *extends* `DeepKeys`\<`TParentData`\> + +• **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> + +• **TOnMount** *extends* `undefined` \| `FieldValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnChange** *extends* `undefined` \| `FieldValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnChangeAsync** *extends* `undefined` \| `FieldAsyncValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnBlur** *extends* `undefined` \| `FieldValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnBlurAsync** *extends* `undefined` \| `FieldAsyncValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnSubmit** *extends* `undefined` \| `FieldValidateOrFn`\<`TParentData`, `TName`, `TData`\> + +• **TOnSubmitAsync** *extends* `undefined` \| `FieldAsyncValidateOrFn`\<`TParentData`, `TName`, `TData`\> diff --git a/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md b/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md index 60eac66d1..890321467 100644 --- a/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md +++ b/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md @@ -11,7 +11,7 @@ title: FieldComponentProps type FieldComponentProps = UseFieldOptions; ``` -Defined in: [packages/vue-form/src/useField.tsx:400](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L400) +Defined in: [packages/vue-form/src/useField.tsx:364](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L364) ## Type Parameters diff --git a/docs/framework/vue/reference/type-aliases/usefield.md b/docs/framework/vue/reference/type-aliases/usefield.md index 980cd7b48..6a8e8ba5e 100644 --- a/docs/framework/vue/reference/type-aliases/usefield.md +++ b/docs/framework/vue/reference/type-aliases/usefield.md @@ -11,7 +11,7 @@ title: UseField type UseField = (opts) => object; ``` -Defined in: [packages/vue-form/src/useField.tsx:190](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L190) +Defined in: [packages/vue-form/src/useField.tsx:166](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L166) ## Type Parameters @@ -59,7 +59,7 @@ Defined in: [packages/vue-form/src/useField.tsx:190](https://github.com/TanStack ### opts -`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\>, `"form"`\> +`UseFieldOptionsBound`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`\> ## Returns diff --git a/docs/framework/vue/reference/variables/field.md b/docs/framework/vue/reference/variables/field.md index f2fca429d..fef910c9d 100644 --- a/docs/framework/vue/reference/variables/field.md +++ b/docs/framework/vue/reference/variables/field.md @@ -8,17 +8,17 @@ title: Field # Variable: Field() ```ts -const Field: (props) => CreateComponentPublicInstanceWithMixins & object & {} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, {}>; +const Field: (props) => CreateComponentPublicInstanceWithMixins & {} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, {}>; ``` -Defined in: [packages/vue-form/src/useField.tsx:448](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L448) +Defined in: [packages/vue-form/src/useField.tsx:442](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L442) ## Parameters ### props -FieldApiOptions\ & \{ ...; \} & (\{ ...; \} \| \{ ...; \}) & `VNodeProps` & `AllowedComponentProps` & `ComponentCustomProps` +UseFieldOptions\ & (\{ ...; \} \| \{ ...; \}) & `VNodeProps` & `AllowedComponentProps` & `ComponentCustomProps` ## Returns -`CreateComponentPublicInstanceWithMixins`\<`FieldApiOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\> & `object` & \{\} \| \{\}, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, \{\}\> +`CreateComponentPublicInstanceWithMixins`\<`UseFieldOptions`\<`TParentData`, `TName`, `TData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TFormOnMount`, `TFormOnChange`, `TFormOnChangeAsync`, `TFormOnBlur`, `TFormOnBlurAsync`, `TFormOnSubmit`, `TFormOnSubmitAsync`, `TFormOnServer`, `TParentSubmitMeta`\> & \{\} \| \{\}, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, \{\}\> diff --git a/docs/reference/classes/fieldapi.md b/docs/reference/classes/fieldapi.md index c0e1a3348..34df8b000 100644 --- a/docs/reference/classes/fieldapi.md +++ b/docs/reference/classes/fieldapi.md @@ -7,7 +7,7 @@ title: FieldApi # Class: FieldApi\ -Defined in: [packages/form-core/src/FieldApi.ts:860](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L860) +Defined in: [packages/form-core/src/FieldApi.ts:842](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L842) A class representing the API for managing a form field. @@ -65,7 +65,7 @@ the `new FieldApi` constructor. new FieldApi(opts): FieldApi ``` -Defined in: [packages/form-core/src/FieldApi.ts:974](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L974) +Defined in: [packages/form-core/src/FieldApi.ts:970](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L970) Initializes a new `FieldApi` instance. @@ -87,7 +87,7 @@ Initializes a new `FieldApi` instance. form: FormApi; ``` -Defined in: [packages/form-core/src/FieldApi.ts:890](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L890) +Defined in: [packages/form-core/src/FieldApi.ts:886](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L886) A reference to the form API instance. @@ -96,10 +96,10 @@ A reference to the form API instance. ### name ```ts -name: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never; +name: DeepKeys; ``` -Defined in: [packages/form-core/src/FieldApi.ts:914](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L914) +Defined in: [packages/form-core/src/FieldApi.ts:910](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L910) The field name. @@ -111,7 +111,7 @@ The field name. options: FieldApiOptions; ``` -Defined in: [packages/form-core/src/FieldApi.ts:918](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L918) +Defined in: [packages/form-core/src/FieldApi.ts:914](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L914) The field options. @@ -123,7 +123,7 @@ The field options. store: Derived>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:942](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L942) +Defined in: [packages/form-core/src/FieldApi.ts:938](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L938) The field state store. @@ -135,7 +135,7 @@ The field state store. timeoutIds: Record; ``` -Defined in: [packages/form-core/src/FieldApi.ts:969](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L969) +Defined in: [packages/form-core/src/FieldApi.ts:965](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L965) ## Accessors @@ -147,7 +147,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:969](https://github.com/TanStack get state(): FieldState ``` -Defined in: [packages/form-core/src/FieldApi.ts:966](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L966) +Defined in: [packages/form-core/src/FieldApi.ts:962](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L962) The current field state. @@ -163,7 +163,7 @@ The current field state. getInfo(): FieldInfo ``` -Defined in: [packages/form-core/src/FieldApi.ts:1222](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1222) +Defined in: [packages/form-core/src/FieldApi.ts:1218](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1218) Gets the field information object. @@ -179,7 +179,7 @@ Gets the field information object. getMeta(): FieldMeta ``` -Defined in: [packages/form-core/src/FieldApi.ts:1190](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1190) +Defined in: [packages/form-core/src/FieldApi.ts:1186](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1186) #### Returns @@ -193,7 +193,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:1190](https://github.com/TanStac getValue(): TData ``` -Defined in: [packages/form-core/src/FieldApi.ts:1172](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1172) +Defined in: [packages/form-core/src/FieldApi.ts:1168](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1168) Gets the current field value. @@ -213,7 +213,7 @@ Use `field.state.value` instead. handleBlur(): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1632](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1632) +Defined in: [packages/form-core/src/FieldApi.ts:1625](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1625) Handles the blur event. @@ -229,7 +229,7 @@ Handles the blur event. handleChange(updater): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1625](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1625) +Defined in: [packages/form-core/src/FieldApi.ts:1618](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1618) Handles the change event. @@ -254,7 +254,7 @@ insertValue( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1242](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1242) +Defined in: [packages/form-core/src/FieldApi.ts:1238](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1238) Inserts a value at the specified index, shifting the subsequent values to the right. @@ -284,7 +284,7 @@ Inserts a value at the specified index, shifting the subsequent values to the ri mount(): () => void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1067](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1067) +Defined in: [packages/form-core/src/FieldApi.ts:1063](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1063) Mounts the field instance to the form. @@ -307,7 +307,7 @@ moveValue( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1298](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1298) +Defined in: [packages/form-core/src/FieldApi.ts:1294](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1294) Moves the value at the first specified index to the second specified index. @@ -337,7 +337,7 @@ Moves the value at the first specified index to the second specified index. pushValue(value, opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1227](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1227) +Defined in: [packages/form-core/src/FieldApi.ts:1223](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1223) Pushes a new value to the field. @@ -363,7 +363,7 @@ Pushes a new value to the field. removeValue(index, opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1274](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1274) +Defined in: [packages/form-core/src/FieldApi.ts:1270](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1270) Removes a value at the specified index. @@ -392,7 +392,7 @@ replaceValue( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1258](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1258) +Defined in: [packages/form-core/src/FieldApi.ts:1254](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1254) Replaces a value at the specified index. @@ -422,7 +422,7 @@ Replaces a value at the specified index. setErrorMap(errorMap): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1652](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1652) +Defined in: [packages/form-core/src/FieldApi.ts:1645](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1645) Updates the field's errorMap @@ -444,7 +444,7 @@ Updates the field's errorMap setMeta(updater): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1195](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1195) +Defined in: [packages/form-core/src/FieldApi.ts:1191](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1191) Sets the field metadata. @@ -466,7 +466,7 @@ Sets the field metadata. setValue(updater, options?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1179](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1179) +Defined in: [packages/form-core/src/FieldApi.ts:1175](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1175) Sets the field value and run the `change` validator. @@ -495,7 +495,7 @@ swapValues( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1286](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1286) +Defined in: [packages/form-core/src/FieldApi.ts:1282](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1282) Swaps the values at the specified indices. @@ -525,7 +525,7 @@ Swaps the values at the specified indices. update(opts): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1115](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1115) +Defined in: [packages/form-core/src/FieldApi.ts:1111](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1111) Updates the field instance with new options. @@ -547,7 +547,7 @@ Updates the field instance with new options. validate(cause, opts?): unknown[] | Promise ``` -Defined in: [packages/form-core/src/FieldApi.ts:1592](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1592) +Defined in: [packages/form-core/src/FieldApi.ts:1585](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1585) Validates the field value. diff --git a/docs/reference/classes/formapi.md b/docs/reference/classes/formapi.md index ac324a1fa..66df9fa42 100644 --- a/docs/reference/classes/formapi.md +++ b/docs/reference/classes/formapi.md @@ -74,7 +74,7 @@ Defined in: [packages/form-core/src/FormApi.ts:691](https://github.com/TanStack/ ### fieldInfo ```ts -fieldInfo: Record ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TFormData extends any[] ? PrefixArrayAccessor, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor, []> : TFormData extends string | number | bigint | boolean ? "" : never, FieldInfo>; +fieldInfo: Record, FieldInfo>; ``` Defined in: [packages/form-core/src/FormApi.ts:721](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L721) @@ -86,7 +86,7 @@ A record of field information for each field in the form. ### fieldMetaDerived ```ts -fieldMetaDerived: Derived ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TFormData extends any[] ? PrefixArrayAccessor, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor, []> : TFormData extends string | number | bigint | boolean ? "" : never, AnyFieldMeta>>; +fieldMetaDerived: Derived, AnyFieldMeta>>; ``` Defined in: [packages/form-core/src/FormApi.ts:704](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L704) @@ -127,7 +127,7 @@ Defined in: [packages/form-core/src/FormApi.ts:723](https://github.com/TanStack/ ##### Returns -[`FormState`](../type-aliases/formstate.md)\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`\> +[`FormState`](../interfaces/formstate.md)\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`\> ## Methods @@ -141,7 +141,7 @@ Defined in: [packages/form-core/src/FormApi.ts:1772](https://github.com/TanStack #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -218,7 +218,7 @@ Gets the field info of the specified field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -244,7 +244,7 @@ Gets the metadata of the specified field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -270,7 +270,7 @@ Gets the value of the specified field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -336,7 +336,7 @@ Defined in: [packages/form-core/src/FormApi.ts:1811](https://github.com/TanStack #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -350,7 +350,7 @@ Defined in: [packages/form-core/src/FormApi.ts:1811](https://github.com/TanStack ##### value -[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\> *extends* `any`[] ? `any`[] & [`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\>\[`number`\] : `never` +[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\> *extends* `any`[] ? [`DeepValue`](../type-aliases/deepvalue.md)\<[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\>\>\[`number`\] : `never` ##### opts? @@ -396,7 +396,7 @@ Moves the value at the first specified index to the second specified index withi #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -437,7 +437,7 @@ Pushes a value into an array field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -447,7 +447,7 @@ Pushes a value into an array field. ##### value -[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\> *extends* `any`[] ? `any`[] & [`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\>\[`number`\] : `never` +[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\> *extends* `any`[] ? [`DeepValue`](../type-aliases/deepvalue.md)\<[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\>\>\[`number`\] : `never` ##### opts? @@ -474,7 +474,7 @@ Removes a value from an array field at the specified index. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -512,7 +512,7 @@ Replaces a value into an array field at the specified index. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -526,7 +526,7 @@ Replaces a value into an array field at the specified index. ##### value -[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\> *extends* `any`[] ? `any`[] & [`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\>\[`number`\] : `never` +[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\> *extends* `any`[] ? [`DeepValue`](../type-aliases/deepvalue.md)\<[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\>\>\[`number`\] : `never` ##### opts? @@ -583,7 +583,7 @@ Resets the field value and meta to default state #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -609,7 +609,7 @@ resets every field's meta #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -657,7 +657,7 @@ Updates the metadata of the specified field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -690,7 +690,7 @@ Sets the value of the specified field and optionally updates the touched state. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -700,7 +700,7 @@ Sets the value of the specified field and optionally updates the touched state. ##### updater -[`Updater`](../type-aliases/updater.md)\<[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`, \[\]\>\> +[`Updater`](../type-aliases/updater.md)\<[`DeepValue`](../type-aliases/deepvalue.md)\<`TFormData`, `TField`\>\> ##### opts? @@ -728,7 +728,7 @@ Swaps the values at the specified indices within an array field. #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -813,7 +813,7 @@ Validates the children of a specified array in the form starting from a given in #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters @@ -847,7 +847,7 @@ Validates a specified field in the form using the correct handlers for a given v #### Type Parameters -• **TField** *extends* `string` \| `number` +• **TField** *extends* `string` #### Parameters diff --git a/docs/reference/functions/mergeform.md b/docs/reference/functions/mergeform.md index 24238089b..25d3a54e3 100644 --- a/docs/reference/functions/mergeform.md +++ b/docs/reference/functions/mergeform.md @@ -25,7 +25,7 @@ Defined in: [packages/form-core/src/mergeForm.ts:73](https://github.com/TanStack ### state -`Partial`\<[`FormState`](../type-aliases/formstate.md)\<`TFormData`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\>\> +`Partial`\<[`FormState`](../interfaces/formstate.md)\<`TFormData`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\>\> ## Returns diff --git a/docs/reference/index.md b/docs/reference/index.md index a87090a70..8a5914f41 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -19,19 +19,28 @@ title: "@tanstack/form-core" - [FieldOptions](interfaces/fieldoptions.md) - [FieldValidators](interfaces/fieldvalidators.md) - [FormOptions](interfaces/formoptions.md) +- [FormState](interfaces/formstate.md) - [FormValidators](interfaces/formvalidators.md) - [StandardSchemaV1Issue](interfaces/standardschemav1issue.md) ## Type Aliases +- [AllObjectKeys](type-aliases/allobjectkeys.md) +- [AllTupleKeys](type-aliases/alltuplekeys.md) - [AnyFieldApi](type-aliases/anyfieldapi.md) - [AnyFieldMeta](type-aliases/anyfieldmeta.md) - [AnyFieldMetaBase](type-aliases/anyfieldmetabase.md) - [AnyFieldMetaDerived](type-aliases/anyfieldmetaderived.md) - [AnyFormApi](type-aliases/anyformapi.md) - [AnyFormState](type-aliases/anyformstate.md) +- [ArrayAccessor](type-aliases/arrayaccessor.md) - [BaseFormState](type-aliases/baseformstate.md) - [DeepKeys](type-aliases/deepkeys.md) +- [DeepRecord](type-aliases/deeprecord.md) +- [DeepRecordArrayUnion](type-aliases/deeprecordarrayunion.md) +- [DeepRecordObjectUnion](type-aliases/deeprecordobjectunion.md) +- [DeepRecordTupleUnion](type-aliases/deeprecordtupleunion.md) +- [DeepRecordUnion](type-aliases/deeprecordunion.md) - [DeepValue](type-aliases/deepvalue.md) - [DerivedFormState](type-aliases/derivedformstate.md) - [FieldInfo](type-aliases/fieldinfo.md) @@ -39,12 +48,14 @@ title: "@tanstack/form-core" - [FieldMetaBase](type-aliases/fieldmetabase.md) - [FieldMetaDerived](type-aliases/fieldmetaderived.md) - [FieldState](type-aliases/fieldstate.md) -- [FormState](type-aliases/formstate.md) - [FormValidateFn](type-aliases/formvalidatefn.md) - [FormValidationError](type-aliases/formvalidationerror.md) - [FormValidator](type-aliases/formvalidator.md) +- [ObjectAccessor](type-aliases/objectaccessor.md) - [StandardSchemaV1](type-aliases/standardschemav1.md) - [TStandardSchemaValidatorValue](type-aliases/tstandardschemavalidatorvalue.md) +- [TupleAccessor](type-aliases/tupleaccessor.md) +- [UnionToIntersection](type-aliases/uniontointersection.md) - [UnwrapFieldAsyncValidateOrFn](type-aliases/unwrapfieldasyncvalidateorfn.md) - [UnwrapFieldValidateOrFn](type-aliases/unwrapfieldvalidateorfn.md) - [UnwrapFormAsyncValidateOrFn](type-aliases/unwrapformasyncvalidateorfn.md) diff --git a/docs/reference/interfaces/fieldapioptions.md b/docs/reference/interfaces/fieldapioptions.md index c73810aa1..ced5f164b 100644 --- a/docs/reference/interfaces/fieldapioptions.md +++ b/docs/reference/interfaces/fieldapioptions.md @@ -7,7 +7,7 @@ title: FieldApiOptions # Interface: FieldApiOptions\ -Defined in: [packages/form-core/src/FieldApi.ts:448](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L448) +Defined in: [packages/form-core/src/FieldApi.ts:446](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L446) An object type representing the required options for the FieldApi class. @@ -63,7 +63,7 @@ An object type representing the required options for the FieldApi class. optional asyncAlways: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:395](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L395) +Defined in: [packages/form-core/src/FieldApi.ts:393](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L393) If `true`, always run async validation, even if there are errors emitted during synchronous validation. @@ -79,7 +79,7 @@ If `true`, always run async validation, even if there are errors emitted during optional asyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:391](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L391) +Defined in: [packages/form-core/src/FieldApi.ts:389](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L389) The default time to debounce async validation if there is not a more specific debounce time passed. @@ -95,7 +95,7 @@ The default time to debounce async validation if there is not a more specific de optional defaultMeta: Partial>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:414](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L414) +Defined in: [packages/form-core/src/FieldApi.ts:412](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L412) An optional object with default metadata for the field. @@ -111,7 +111,7 @@ An optional object with default metadata for the field. optional defaultValue: NoInfer; ``` -Defined in: [packages/form-core/src/FieldApi.ts:387](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L387) +Defined in: [packages/form-core/src/FieldApi.ts:385](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L385) An optional default value for the field. @@ -127,7 +127,7 @@ An optional default value for the field. optional disableErrorFlat: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:442](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L442) +Defined in: [packages/form-core/src/FieldApi.ts:440](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L440) Disable the `flat(1)` operation on `field.errors`. This is useful if you want to keep the error structure as is. Not suggested for most use-cases. @@ -143,7 +143,7 @@ Disable the `flat(1)` operation on `field.errors`. This is useful if you want to form: FormApi; ``` -Defined in: [packages/form-core/src/FieldApi.ts:486](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L486) +Defined in: [packages/form-core/src/FieldApi.ts:498](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L498) *** @@ -153,7 +153,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:486](https://github.com/TanStack optional listeners: FieldListeners; ``` -Defined in: [packages/form-core/src/FieldApi.ts:438](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L438) +Defined in: [packages/form-core/src/FieldApi.ts:436](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L436) A list of listeners which attach to the corresponding events @@ -169,7 +169,7 @@ A list of listeners which attach to the corresponding events name: TName; ``` -Defined in: [packages/form-core/src/FieldApi.ts:383](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L383) +Defined in: [packages/form-core/src/FieldApi.ts:381](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L381) The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -185,7 +185,7 @@ The field name. The type will be `DeepKeys` to ensure your name is optional validators: FieldValidators; ``` -Defined in: [packages/form-core/src/FieldApi.ts:399](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L399) +Defined in: [packages/form-core/src/FieldApi.ts:397](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L397) A list of validators to pass to the field diff --git a/docs/reference/interfaces/fieldlisteners.md b/docs/reference/interfaces/fieldlisteners.md index 330a39c14..7c64c8e01 100644 --- a/docs/reference/interfaces/fieldlisteners.md +++ b/docs/reference/interfaces/fieldlisteners.md @@ -7,7 +7,7 @@ title: FieldListeners # Interface: FieldListeners\ -Defined in: [packages/form-core/src/FieldApi.ts:348](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L348) +Defined in: [packages/form-core/src/FieldApi.ts:346](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L346) ## Type Parameters @@ -25,7 +25,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:348](https://github.com/TanStack optional onBlur: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:354](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L354) +Defined in: [packages/form-core/src/FieldApi.ts:352](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L352) *** @@ -35,7 +35,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:354](https://github.com/TanStack optional onChange: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:353](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L353) +Defined in: [packages/form-core/src/FieldApi.ts:351](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L351) *** @@ -45,7 +45,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:353](https://github.com/TanStack optional onMount: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:355](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L355) +Defined in: [packages/form-core/src/FieldApi.ts:353](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L353) *** @@ -55,4 +55,4 @@ Defined in: [packages/form-core/src/FieldApi.ts:355](https://github.com/TanStack optional onSubmit: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:356](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L356) +Defined in: [packages/form-core/src/FieldApi.ts:354](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L354) diff --git a/docs/reference/interfaces/fieldoptions.md b/docs/reference/interfaces/fieldoptions.md index f2c0e7467..a433202be 100644 --- a/docs/reference/interfaces/fieldoptions.md +++ b/docs/reference/interfaces/fieldoptions.md @@ -7,7 +7,7 @@ title: FieldOptions # Interface: FieldOptions\ -Defined in: [packages/form-core/src/FieldApi.ts:362](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L362) +Defined in: [packages/form-core/src/FieldApi.ts:360](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L360) An object type representing the options for a field in a form. @@ -45,7 +45,7 @@ An object type representing the options for a field in a form. optional asyncAlways: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:395](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L395) +Defined in: [packages/form-core/src/FieldApi.ts:393](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L393) If `true`, always run async validation, even if there are errors emitted during synchronous validation. @@ -57,7 +57,7 @@ If `true`, always run async validation, even if there are errors emitted during optional asyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:391](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L391) +Defined in: [packages/form-core/src/FieldApi.ts:389](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L389) The default time to debounce async validation if there is not a more specific debounce time passed. @@ -69,7 +69,7 @@ The default time to debounce async validation if there is not a more specific de optional defaultMeta: Partial>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:414](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L414) +Defined in: [packages/form-core/src/FieldApi.ts:412](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L412) An optional object with default metadata for the field. @@ -81,7 +81,7 @@ An optional object with default metadata for the field. optional defaultValue: NoInfer; ``` -Defined in: [packages/form-core/src/FieldApi.ts:387](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L387) +Defined in: [packages/form-core/src/FieldApi.ts:385](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L385) An optional default value for the field. @@ -93,7 +93,7 @@ An optional default value for the field. optional disableErrorFlat: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:442](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L442) +Defined in: [packages/form-core/src/FieldApi.ts:440](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L440) Disable the `flat(1)` operation on `field.errors`. This is useful if you want to keep the error structure as is. Not suggested for most use-cases. @@ -105,7 +105,7 @@ Disable the `flat(1)` operation on `field.errors`. This is useful if you want to optional listeners: FieldListeners; ``` -Defined in: [packages/form-core/src/FieldApi.ts:438](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L438) +Defined in: [packages/form-core/src/FieldApi.ts:436](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L436) A list of listeners which attach to the corresponding events @@ -117,7 +117,7 @@ A list of listeners which attach to the corresponding events name: TName; ``` -Defined in: [packages/form-core/src/FieldApi.ts:383](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L383) +Defined in: [packages/form-core/src/FieldApi.ts:381](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L381) The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -129,6 +129,6 @@ The field name. The type will be `DeepKeys` to ensure your name is optional validators: FieldValidators; ``` -Defined in: [packages/form-core/src/FieldApi.ts:399](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L399) +Defined in: [packages/form-core/src/FieldApi.ts:397](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L397) A list of validators to pass to the field diff --git a/docs/reference/interfaces/fieldvalidators.md b/docs/reference/interfaces/fieldvalidators.md index 7705e008f..321e28081 100644 --- a/docs/reference/interfaces/fieldvalidators.md +++ b/docs/reference/interfaces/fieldvalidators.md @@ -7,7 +7,7 @@ title: FieldValidators # Interface: FieldValidators\ -Defined in: [packages/form-core/src/FieldApi.ts:267](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L267) +Defined in: [packages/form-core/src/FieldApi.ts:265](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L265) ## Type Parameters @@ -39,7 +39,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:267](https://github.com/TanStack optional onBlur: TOnBlur; ``` -Defined in: [packages/form-core/src/FieldApi.ts:316](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L316) +Defined in: [packages/form-core/src/FieldApi.ts:314](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L314) An optional function, that runs on the blur event of input. @@ -57,7 +57,7 @@ z.string().min(1) optional onBlurAsync: TOnBlurAsync; ``` -Defined in: [packages/form-core/src/FieldApi.ts:322](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L322) +Defined in: [packages/form-core/src/FieldApi.ts:320](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L320) An optional property similar to `onBlur` but async validation. @@ -75,7 +75,7 @@ z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' }) optional onBlurAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:329](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L329) +Defined in: [packages/form-core/src/FieldApi.ts:327](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L327) An optional number to represent how long the `onBlurAsync` should wait before running @@ -86,10 +86,10 @@ If set to a number larger than 0, will debounce the async validation event by th ### onBlurListenTo? ```ts -optional onBlurListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never[]; +optional onBlurListenTo: DeepKeys[]; ``` -Defined in: [packages/form-core/src/FieldApi.ts:333](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L333) +Defined in: [packages/form-core/src/FieldApi.ts:331](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L331) An optional list of field names that should trigger this field's `onBlur` and `onBlurAsync` events when its value changes @@ -101,7 +101,7 @@ An optional list of field names that should trigger this field's `onBlur` and `o optional onChange: TOnChange; ``` -Defined in: [packages/form-core/src/FieldApi.ts:294](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L294) +Defined in: [packages/form-core/src/FieldApi.ts:292](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L292) An optional function, that runs on the change event of input. @@ -119,7 +119,7 @@ z.string().min(1) optional onChangeAsync: TOnChangeAsync; ``` -Defined in: [packages/form-core/src/FieldApi.ts:300](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L300) +Defined in: [packages/form-core/src/FieldApi.ts:298](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L298) An optional property similar to `onChange` but async validation @@ -137,7 +137,7 @@ z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' }) optional onChangeAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:306](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L306) +Defined in: [packages/form-core/src/FieldApi.ts:304](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L304) An optional number to represent how long the `onChangeAsync` should wait before running @@ -148,10 +148,10 @@ If set to a number larger than 0, will debounce the async validation event by th ### onChangeListenTo? ```ts -optional onChangeListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never[]; +optional onChangeListenTo: DeepKeys[]; ``` -Defined in: [packages/form-core/src/FieldApi.ts:310](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L310) +Defined in: [packages/form-core/src/FieldApi.ts:308](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L308) An optional list of field names that should trigger this field's `onChange` and `onChangeAsync` events when its value changes @@ -163,7 +163,7 @@ An optional list of field names that should trigger this field's `onChange` and optional onMount: TOnMount; ``` -Defined in: [packages/form-core/src/FieldApi.ts:288](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L288) +Defined in: [packages/form-core/src/FieldApi.ts:286](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L286) An optional function, that runs on the mount event of input. @@ -175,7 +175,7 @@ An optional function, that runs on the mount event of input. optional onSubmit: TOnSubmit; ``` -Defined in: [packages/form-core/src/FieldApi.ts:339](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L339) +Defined in: [packages/form-core/src/FieldApi.ts:337](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L337) An optional function, that runs on the submit event of form. @@ -193,7 +193,7 @@ z.string().min(1) optional onSubmitAsync: TOnSubmitAsync; ``` -Defined in: [packages/form-core/src/FieldApi.ts:345](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L345) +Defined in: [packages/form-core/src/FieldApi.ts:343](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L343) An optional property similar to `onSubmit` but async validation. diff --git a/docs/reference/interfaces/formstate.md b/docs/reference/interfaces/formstate.md new file mode 100644 index 000000000..3236cc2f0 --- /dev/null +++ b/docs/reference/interfaces/formstate.md @@ -0,0 +1,452 @@ +--- +id: FormState +title: FormState +--- + + + +# Interface: FormState\ + +Defined in: [packages/form-core/src/FormApi.ts:540](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L540) + +An object representing the current state of the form. + +## Extends + +- [`BaseFormState`](../type-aliases/baseformstate.md)\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`\>.[`DerivedFormState`](../type-aliases/derivedformstate.md)\<`TFormData`, `TOnMount`, `TOnChange`, `TOnChangeAsync`, `TOnBlur`, `TOnBlurAsync`, `TOnSubmit`, `TOnSubmitAsync`, `TOnServer`\> + +## Type Parameters + +• **TFormData** + +• **TOnMount** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> + +• **TOnChange** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> + +• **TOnChangeAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> + +• **TOnBlur** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> + +• **TOnBlurAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> + +• **TOnSubmit** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> + +• **TOnSubmitAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> + +• **TOnServer** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> + +## Properties + +### \_force\_re\_eval? + +```ts +optional _force_re_eval: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:467](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L467) + +@private, used to force a re-evaluation of the form state when options change + +#### Inherited from + +```ts +BaseFormState._force_re_eval +``` + +*** + +### canSubmit + +```ts +canSubmit: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:533](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L533) + +A boolean indicating if the form can be submitted based on its current state. + +#### Inherited from + +```ts +DerivedFormState.canSubmit +``` + +*** + +### errorMap + +```ts +errorMap: FormValidationErrorMap, UnwrapFormValidateOrFn, UnwrapFormAsyncValidateOrFn, UnwrapFormValidateOrFn, UnwrapFormAsyncValidateOrFn, UnwrapFormValidateOrFn, UnwrapFormAsyncValidateOrFn, UnwrapFormAsyncValidateOrFn>; +``` + +Defined in: [packages/form-core/src/FormApi.ts:413](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L413) + +The error map for the form itself. + +#### Inherited from + +```ts +BaseFormState.errorMap +``` + +*** + +### errors + +```ts +errors: ( + | UnwrapFormValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormAsyncValidateOrFn)[]; +``` + +Defined in: [packages/form-core/src/FormApi.ts:492](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L492) + +The error array for the form itself. + +#### Inherited from + +```ts +DerivedFormState.errors +``` + +*** + +### fieldMeta + +```ts +fieldMeta: Record, AnyFieldMeta>; +``` + +Defined in: [packages/form-core/src/FormApi.ts:537](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L537) + +A record of field metadata for each field in the form. + +#### Inherited from + +```ts +DerivedFormState.fieldMeta +``` + +*** + +### fieldMetaBase + +```ts +fieldMetaBase: Record, AnyFieldMetaBase>; +``` + +Defined in: [packages/form-core/src/FormApi.ts:430](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L430) + +A record of field metadata for each field in the form, not including the derived properties, like `errors` and such + +#### Inherited from + +```ts +BaseFormState.fieldMetaBase +``` + +*** + +### isBlurred + +```ts +isBlurred: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:517](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L517) + +A boolean indicating if any of the form fields have been blurred. + +#### Inherited from + +```ts +DerivedFormState.isBlurred +``` + +*** + +### isDirty + +```ts +isDirty: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:521](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L521) + +A boolean indicating if any of the form's fields' values have been modified by the user. `True` if the user have modified at least one of the fields. Opposite of `isPristine`. + +#### Inherited from + +```ts +DerivedFormState.isDirty +``` + +*** + +### isFieldsValid + +```ts +isFieldsValid: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:509](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L509) + +A boolean indicating if all the form fields are valid. + +#### Inherited from + +```ts +DerivedFormState.isFieldsValid +``` + +*** + +### isFieldsValidating + +```ts +isFieldsValidating: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:505](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L505) + +A boolean indicating if any of the form fields are currently validating. + +#### Inherited from + +```ts +DerivedFormState.isFieldsValidating +``` + +*** + +### isFormValid + +```ts +isFormValid: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:488](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L488) + +A boolean indicating if the form is valid. + +#### Inherited from + +```ts +DerivedFormState.isFormValid +``` + +*** + +### isFormValidating + +```ts +isFormValidating: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:484](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L484) + +A boolean indicating if the form is currently validating. + +#### Inherited from + +```ts +DerivedFormState.isFormValidating +``` + +*** + +### isPristine + +```ts +isPristine: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:525](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L525) + +A boolean indicating if none of the form's fields' values have been modified by the user. `True` if the user have not modified any of the fields. Opposite of `isDirty`. + +#### Inherited from + +```ts +DerivedFormState.isPristine +``` + +*** + +### isSubmitSuccessful + +```ts +isSubmitSuccessful: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:463](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L463) + +A boolean indicating if the last submission was successful. + +#### Inherited from + +```ts +BaseFormState.isSubmitSuccessful +``` + +*** + +### isSubmitted + +```ts +isSubmitted: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:451](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L451) + +A boolean indicating if the `onSubmit` function has completed successfully. + +Goes back to `false` at each new submission attempt. + +Note: you can use isSubmitting to check if the form is currently submitting. + +#### Inherited from + +```ts +BaseFormState.isSubmitted +``` + +*** + +### isSubmitting + +```ts +isSubmitting: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:443](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L443) + +A boolean indicating if the form is currently in the process of being submitted after `handleSubmit` is called. + +Goes back to `false` when submission completes for one of the following reasons: +- the validation step returned errors. +- the `onSubmit` function has completed. + +Note: if you're running async operations in your `onSubmit` function make sure to await them to ensure `isSubmitting` is set to `false` only when the async operation completes. + +This is useful for displaying loading indicators or disabling form inputs during submission. + +#### Inherited from + +```ts +BaseFormState.isSubmitting +``` + +*** + +### isTouched + +```ts +isTouched: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:513](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L513) + +A boolean indicating if any of the form fields have been touched. + +#### Inherited from + +```ts +DerivedFormState.isTouched +``` + +*** + +### isValid + +```ts +isValid: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:529](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L529) + +A boolean indicating if the form and all its fields are valid. + +#### Inherited from + +```ts +DerivedFormState.isValid +``` + +*** + +### isValidating + +```ts +isValidating: boolean; +``` + +Defined in: [packages/form-core/src/FormApi.ts:455](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L455) + +A boolean indicating if the form or any of its fields are currently validating. + +#### Inherited from + +```ts +BaseFormState.isValidating +``` + +*** + +### submissionAttempts + +```ts +submissionAttempts: number; +``` + +Defined in: [packages/form-core/src/FormApi.ts:459](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L459) + +A counter for tracking the number of submission attempts. + +#### Inherited from + +```ts +BaseFormState.submissionAttempts +``` + +*** + +### validationMetaMap + +```ts +validationMetaMap: Record<"onChange" | "onBlur" | "onSubmit" | "onMount" | "onServer", undefined | ValidationMeta>; +``` + +Defined in: [packages/form-core/src/FormApi.ts:426](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L426) + +An internal mechanism used for keeping track of validation logic in a form. + +#### Inherited from + +```ts +BaseFormState.validationMetaMap +``` + +*** + +### values + +```ts +values: TFormData; +``` + +Defined in: [packages/form-core/src/FormApi.ts:409](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L409) + +The current values of the form fields. + +#### Inherited from + +```ts +BaseFormState.values +``` diff --git a/docs/reference/type-aliases/allobjectkeys.md b/docs/reference/type-aliases/allobjectkeys.md new file mode 100644 index 000000000..24ccda39a --- /dev/null +++ b/docs/reference/type-aliases/allobjectkeys.md @@ -0,0 +1,18 @@ +--- +id: AllObjectKeys +title: AllObjectKeys +--- + + + +# Type Alias: AllObjectKeys\ + +```ts +type AllObjectKeys = T extends any ? keyof T & string | number : never; +``` + +Defined in: [packages/form-core/src/util-types.ts:56](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L56) + +## Type Parameters + +• **T** diff --git a/docs/reference/type-aliases/alltuplekeys.md b/docs/reference/type-aliases/alltuplekeys.md new file mode 100644 index 000000000..bbaeb5ce9 --- /dev/null +++ b/docs/reference/type-aliases/alltuplekeys.md @@ -0,0 +1,18 @@ +--- +id: AllTupleKeys +title: AllTupleKeys +--- + + + +# Type Alias: AllTupleKeys\ + +```ts +type AllTupleKeys = T extends any ? keyof T & `${number}` : never; +``` + +Defined in: [packages/form-core/src/util-types.ts:41](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L41) + +## Type Parameters + +• **T** diff --git a/docs/reference/type-aliases/anyfieldapi.md b/docs/reference/type-aliases/anyfieldapi.md index 29dca6dd7..3f5b3063c 100644 --- a/docs/reference/type-aliases/anyfieldapi.md +++ b/docs/reference/type-aliases/anyfieldapi.md @@ -11,6 +11,6 @@ title: AnyFieldApi type AnyFieldApi = FieldApi; ``` -Defined in: [packages/form-core/src/FieldApi.ts:829](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L829) +Defined in: [packages/form-core/src/FieldApi.ts:811](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L811) A type representing the Field API with all generics set to `any` for convenience. diff --git a/docs/reference/type-aliases/anyfieldmeta.md b/docs/reference/type-aliases/anyfieldmeta.md index a3e95d97e..8b84f14d6 100644 --- a/docs/reference/type-aliases/anyfieldmeta.md +++ b/docs/reference/type-aliases/anyfieldmeta.md @@ -11,4 +11,4 @@ title: AnyFieldMeta type AnyFieldMeta = FieldMeta; ``` -Defined in: [packages/form-core/src/FieldApi.ts:748](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L748) +Defined in: [packages/form-core/src/FieldApi.ts:730](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L730) diff --git a/docs/reference/type-aliases/anyfieldmetabase.md b/docs/reference/type-aliases/anyfieldmetabase.md index db1e9aba8..61ef8ceee 100644 --- a/docs/reference/type-aliases/anyfieldmetabase.md +++ b/docs/reference/type-aliases/anyfieldmetabase.md @@ -11,4 +11,4 @@ title: AnyFieldMetaBase type AnyFieldMetaBase = FieldMetaBase; ``` -Defined in: [packages/form-core/src/FieldApi.ts:570](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L570) +Defined in: [packages/form-core/src/FieldApi.ts:567](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L567) diff --git a/docs/reference/type-aliases/anyfieldmetaderived.md b/docs/reference/type-aliases/anyfieldmetaderived.md index 8abfa0848..6189f393c 100644 --- a/docs/reference/type-aliases/anyfieldmetaderived.md +++ b/docs/reference/type-aliases/anyfieldmetaderived.md @@ -11,4 +11,4 @@ title: AnyFieldMetaDerived type AnyFieldMetaDerived = FieldMetaDerived; ``` -Defined in: [packages/form-core/src/FieldApi.ts:662](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L662) +Defined in: [packages/form-core/src/FieldApi.ts:644](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L644) diff --git a/docs/reference/type-aliases/arrayaccessor.md b/docs/reference/type-aliases/arrayaccessor.md new file mode 100644 index 000000000..e5d50d648 --- /dev/null +++ b/docs/reference/type-aliases/arrayaccessor.md @@ -0,0 +1,18 @@ +--- +id: ArrayAccessor +title: ArrayAccessor +--- + + + +# Type Alias: ArrayAccessor\ + +```ts +type ArrayAccessor = `${TPrefix}[${number}]`; +``` + +Defined in: [packages/form-core/src/util-types.ts:24](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L24) + +## Type Parameters + +• **TPrefix** *extends* `string` diff --git a/docs/reference/type-aliases/deepkeys.md b/docs/reference/type-aliases/deepkeys.md index 64559e493..cd0969ce6 100644 --- a/docs/reference/type-aliases/deepkeys.md +++ b/docs/reference/type-aliases/deepkeys.md @@ -5,18 +5,16 @@ title: DeepKeys -# Type Alias: DeepKeys\ +# Type Alias: DeepKeys\ ```ts -type DeepKeys = TDepth["length"] extends 5 ? never : unknown extends T ? PrefixFromDepth : T extends readonly any[] & IsTuple ? PrefixTupleAccessor, TDepth> : T extends any[] ? PrefixArrayAccessor : T extends Date ? never : T extends object ? PrefixObjectAccessor : T extends string | number | boolean | bigint ? "" : never; +type DeepKeys = unknown extends T ? string : keyof DeepRecord & string; ``` -Defined in: [packages/form-core/src/util-types.ts:70](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L70) +Defined in: [packages/form-core/src/util-types.ts:102](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L102) The keys of an object or array, deeply nested. ## Type Parameters • **T** - -• **TDepth** *extends* `any`[] = \[\] diff --git a/docs/reference/type-aliases/deeprecord.md b/docs/reference/type-aliases/deeprecord.md new file mode 100644 index 000000000..d2462de4b --- /dev/null +++ b/docs/reference/type-aliases/deeprecord.md @@ -0,0 +1,18 @@ +--- +id: DeepRecord +title: DeepRecord +--- + + + +# Type Alias: DeepRecord\ + +```ts +type DeepRecord = UnionToIntersection>; +``` + +Defined in: [packages/form-core/src/util-types.ts:97](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L97) + +## Type Parameters + +• **T** diff --git a/docs/reference/type-aliases/deeprecordarrayunion.md b/docs/reference/type-aliases/deeprecordarrayunion.md new file mode 100644 index 000000000..198640983 --- /dev/null +++ b/docs/reference/type-aliases/deeprecordarrayunion.md @@ -0,0 +1,24 @@ +--- +id: DeepRecordArrayUnion +title: DeepRecordArrayUnion +--- + + + +# Type Alias: DeepRecordArrayUnion\ + +```ts +type DeepRecordArrayUnion = DeepRecordUnion, + | TAcc +| Record, T[number]>>; +``` + +Defined in: [packages/form-core/src/util-types.ts:26](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L26) + +## Type Parameters + +• **T** *extends* `ReadonlyArray`\<`any`\> + +• **TPrefix** *extends* `string` + +• **TAcc** diff --git a/docs/reference/type-aliases/deeprecordobjectunion.md b/docs/reference/type-aliases/deeprecordobjectunion.md new file mode 100644 index 000000000..eca16af6b --- /dev/null +++ b/docs/reference/type-aliases/deeprecordobjectunion.md @@ -0,0 +1,26 @@ +--- +id: DeepRecordObjectUnion +title: DeepRecordObjectUnion +--- + + + +# Type Alias: DeepRecordObjectUnion\ + +```ts +type DeepRecordObjectUnion = TAllKeys extends any ? DeepRecordUnion, + | TAcc + | Record, T[TAllKeys]>> : never; +``` + +Defined in: [packages/form-core/src/util-types.ts:65](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L65) + +## Type Parameters + +• **T** + +• **TPrefix** *extends* `string` + +• **TAcc** + +• **TAllKeys** *extends* [`AllObjectKeys`](allobjectkeys.md)\<`T`\> = [`AllObjectKeys`](allobjectkeys.md)\<`T`\> diff --git a/docs/reference/type-aliases/deeprecordtupleunion.md b/docs/reference/type-aliases/deeprecordtupleunion.md new file mode 100644 index 000000000..9943148f6 --- /dev/null +++ b/docs/reference/type-aliases/deeprecordtupleunion.md @@ -0,0 +1,26 @@ +--- +id: DeepRecordTupleUnion +title: DeepRecordTupleUnion +--- + + + +# Type Alias: DeepRecordTupleUnion\ + +```ts +type DeepRecordTupleUnion = TAllKeys extends any ? DeepRecordUnion, + | TAcc + | Record, T[TAllKeys]>> : never; +``` + +Defined in: [packages/form-core/src/util-types.ts:43](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L43) + +## Type Parameters + +• **T** *extends* `ReadonlyArray`\<`any`\> + +• **TPrefix** *extends* `string` + +• **TAcc** + +• **TAllKeys** *extends* [`AllTupleKeys`](alltuplekeys.md)\<`T`\> = [`AllTupleKeys`](alltuplekeys.md)\<`T`\> diff --git a/docs/reference/type-aliases/deeprecordunion.md b/docs/reference/type-aliases/deeprecordunion.md new file mode 100644 index 000000000..a0931df7f --- /dev/null +++ b/docs/reference/type-aliases/deeprecordunion.md @@ -0,0 +1,22 @@ +--- +id: DeepRecordUnion +title: DeepRecordUnion +--- + + + +# Type Alias: DeepRecordUnion\ + +```ts +type DeepRecordUnion = IsAny extends true ? T : T extends string | number | boolean | bigint | Date ? TAcc : T extends ReadonlyArray ? number extends T["length"] ? DeepRecordArrayUnion : DeepRecordTupleUnion : T extends object ? DeepRecordObjectUnion : TAcc; +``` + +Defined in: [packages/form-core/src/util-types.ts:78](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L78) + +## Type Parameters + +• **T** + +• **TPrefix** *extends* `string` = `""` + +• **TAcc** = `never` diff --git a/docs/reference/type-aliases/deepvalue.md b/docs/reference/type-aliases/deepvalue.md index 22f9dd033..3896a2e4b 100644 --- a/docs/reference/type-aliases/deepvalue.md +++ b/docs/reference/type-aliases/deepvalue.md @@ -5,15 +5,13 @@ title: DeepValue -# Type Alias: DeepValue\ +# Type Alias: DeepValue\ ```ts -type DeepValue = unknown extends TValue ? TValue : TDepth["length"] extends 10 ? unknown : TValue extends ReadonlyArray ? TAccessor extends `[${infer TBrackets}].${infer TAfter}` ? DeepValue, TAfter, [...TDepth, any]> : TAccessor extends `[${infer TBrackets}]` ? DeepValue : TAccessor extends keyof TValue ? TValue[TAccessor] : TValue[TAccessor & number] : TAccessor extends `${infer TBefore}[${infer TEverythingElse}` ? DeepValue, `[${TEverythingElse}`, [...TDepth, any]> : TAccessor extends `[${infer TBrackets}]` ? DeepValue : TAccessor extends `${infer TBefore}.${infer TAfter}` ? DeepValue, TAfter, [...TDepth, any]> : TAccessor extends string ? - | Get - | ApplyNull<...> | ApplyUndefined<...> : never; +type DeepValue = DeepRecord[TAccessor & keyof DeepRecord]; ``` -Defined in: [packages/form-core/src/util-types.ts:104](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L104) +Defined in: [packages/form-core/src/util-types.ts:109](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L109) Infer the type of a deeply nested property within an object or an array. @@ -22,5 +20,3 @@ Infer the type of a deeply nested property within an object or an array. • **TValue** • **TAccessor** - -• **TDepth** *extends* `ReadonlyArray`\<`any`\> = \[\] diff --git a/docs/reference/type-aliases/fieldmeta.md b/docs/reference/type-aliases/fieldmeta.md index 3ae2d54f3..c4d16234a 100644 --- a/docs/reference/type-aliases/fieldmeta.md +++ b/docs/reference/type-aliases/fieldmeta.md @@ -11,7 +11,7 @@ title: FieldMeta type FieldMeta = FieldMetaBase & FieldMetaDerived; ``` -Defined in: [packages/form-core/src/FieldApi.ts:685](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L685) +Defined in: [packages/form-core/src/FieldApi.ts:667](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L667) An object type representing the metadata of a field in a form. diff --git a/docs/reference/type-aliases/fieldmetabase.md b/docs/reference/type-aliases/fieldmetabase.md index 4985d2591..5077778f5 100644 --- a/docs/reference/type-aliases/fieldmetabase.md +++ b/docs/reference/type-aliases/fieldmetabase.md @@ -11,7 +11,7 @@ title: FieldMetaBase type FieldMetaBase = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:500](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L500) +Defined in: [packages/form-core/src/FieldApi.ts:512](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L512) ## Type Parameters @@ -54,7 +54,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:500](https://github.com/TanStack ### errorMap ```ts -errorMap: ValidationErrorMap, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn>; +errorMap: ValidationErrorMap, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn, UnwrapFieldValidateOrFn, UnwrapFieldAsyncValidateOrFn>; ``` A map of errors related to the field value. diff --git a/docs/reference/type-aliases/fieldmetaderived.md b/docs/reference/type-aliases/fieldmetaderived.md index 9face2551..1d2211802 100644 --- a/docs/reference/type-aliases/fieldmetaderived.md +++ b/docs/reference/type-aliases/fieldmetaderived.md @@ -11,7 +11,7 @@ title: FieldMetaDerived type FieldMetaDerived = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:590](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L590) +Defined in: [packages/form-core/src/FieldApi.ts:587](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L587) ## Type Parameters @@ -55,13 +55,13 @@ Defined in: [packages/form-core/src/FieldApi.ts:590](https://github.com/TanStack ```ts errors: ( - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray> - | UnwrapOneLevelOfArray>)[]; + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray> + | UnwrapOneLevelOfArray>)[]; ``` An array of errors related to the field value. diff --git a/docs/reference/type-aliases/fieldstate.md b/docs/reference/type-aliases/fieldstate.md index fea711de2..5bd0e3c85 100644 --- a/docs/reference/type-aliases/fieldstate.md +++ b/docs/reference/type-aliases/fieldstate.md @@ -11,7 +11,7 @@ title: FieldState type FieldState = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:771](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L771) +Defined in: [packages/form-core/src/FieldApi.ts:753](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L753) An object type representing the state of a field. diff --git a/docs/reference/type-aliases/formstate.md b/docs/reference/type-aliases/formstate.md deleted file mode 100644 index 042706dc7..000000000 --- a/docs/reference/type-aliases/formstate.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -id: FormState -title: FormState ---- - - - -# Type Alias: FormState\ - -```ts -type FormState = BaseFormState & DerivedFormState; -``` - -Defined in: [packages/form-core/src/FormApi.ts:540](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L540) - -## Type Parameters - -• **TFormData** - -• **TOnMount** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> - -• **TOnChange** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> - -• **TOnChangeAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> - -• **TOnBlur** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> - -• **TOnBlurAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> - -• **TOnSubmit** *extends* `undefined` \| `FormValidateOrFn`\<`TFormData`\> - -• **TOnSubmitAsync** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> - -• **TOnServer** *extends* `undefined` \| `FormAsyncValidateOrFn`\<`TFormData`\> diff --git a/docs/reference/type-aliases/objectaccessor.md b/docs/reference/type-aliases/objectaccessor.md new file mode 100644 index 000000000..62cf55b8d --- /dev/null +++ b/docs/reference/type-aliases/objectaccessor.md @@ -0,0 +1,20 @@ +--- +id: ObjectAccessor +title: ObjectAccessor +--- + + + +# Type Alias: ObjectAccessor\ + +```ts +type ObjectAccessor = TPrefix extends "" ? `${TKey}` : `${TPrefix}.${TKey}`; +``` + +Defined in: [packages/form-core/src/util-types.ts:60](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L60) + +## Type Parameters + +• **TPrefix** *extends* `string` + +• **TKey** *extends* `string` \| `number` diff --git a/docs/reference/type-aliases/tupleaccessor.md b/docs/reference/type-aliases/tupleaccessor.md new file mode 100644 index 000000000..342caed17 --- /dev/null +++ b/docs/reference/type-aliases/tupleaccessor.md @@ -0,0 +1,20 @@ +--- +id: TupleAccessor +title: TupleAccessor +--- + + + +# Type Alias: TupleAccessor\ + +```ts +type TupleAccessor = `${TPrefix}[${TKey & string}]`; +``` + +Defined in: [packages/form-core/src/util-types.ts:36](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L36) + +## Type Parameters + +• **TPrefix** *extends* `string` + +• **TKey** diff --git a/docs/reference/type-aliases/uniontointersection.md b/docs/reference/type-aliases/uniontointersection.md new file mode 100644 index 000000000..631e7a618 --- /dev/null +++ b/docs/reference/type-aliases/uniontointersection.md @@ -0,0 +1,18 @@ +--- +id: UnionToIntersection +title: UnionToIntersection +--- + + + +# Type Alias: UnionToIntersection\ + +```ts +type UnionToIntersection = T extends any ? (param) => any : never extends (param) => any ? TI : never; +``` + +Defined in: [packages/form-core/src/util-types.ts:91](https://github.com/TanStack/form/blob/main/packages/form-core/src/util-types.ts#L91) + +## Type Parameters + +• **T** diff --git a/docs/reference/type-aliases/unwrapfieldasyncvalidateorfn.md b/docs/reference/type-aliases/unwrapfieldasyncvalidateorfn.md index 678094830..f775de43d 100644 --- a/docs/reference/type-aliases/unwrapfieldasyncvalidateorfn.md +++ b/docs/reference/type-aliases/unwrapfieldasyncvalidateorfn.md @@ -5,22 +5,20 @@ title: UnwrapFieldAsyncValidateOrFn -# Type Alias: UnwrapFieldAsyncValidateOrFn\ +# Type Alias: UnwrapFieldAsyncValidateOrFn\ ```ts -type UnwrapFieldAsyncValidateOrFn = +type UnwrapFieldAsyncValidateOrFn = | [TFormValidateOrFn] extends [StandardSchemaV1] ? TName extends keyof TStandardOut ? StandardSchemaV1Issue[] : undefined : undefined | UnwrapFormAsyncValidateOrFnForInner extends infer TFormValidateVal ? TFormValidateVal extends object ? [DeepValue] extends [never] ? undefined : StandardSchemaV1Issue[] : TFormValidateVal extends object ? TName extends keyof TFormValidateVal["fields"] ? TFormValidateVal["fields"][TName] : undefined : undefined : never | [TValidateOrFn] extends [FieldValidateAsyncFn] ? Awaited> : [TValidateOrFn] extends [StandardSchemaV1] ? StandardSchemaV1Issue[] : undefined; ``` -Defined in: [packages/form-core/src/FieldApi.ts:204](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L204) +Defined in: [packages/form-core/src/FieldApi.ts:203](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L203) ## Type Parameters -• **TParentData** - -• **TName** *extends* [`DeepKeys`](deepkeys.md)\<`TParentData`\> +• **TName** *extends* `string` • **TValidateOrFn** *extends* `undefined` \| `FieldAsyncValidateOrFn`\<`any`, `any`, `any`\> diff --git a/docs/reference/type-aliases/unwrapfieldvalidateorfn.md b/docs/reference/type-aliases/unwrapfieldvalidateorfn.md index 9453bc9bd..5f8b4b354 100644 --- a/docs/reference/type-aliases/unwrapfieldvalidateorfn.md +++ b/docs/reference/type-aliases/unwrapfieldvalidateorfn.md @@ -5,10 +5,10 @@ title: UnwrapFieldValidateOrFn -# Type Alias: UnwrapFieldValidateOrFn\ +# Type Alias: UnwrapFieldValidateOrFn\ ```ts -type UnwrapFieldValidateOrFn = +type UnwrapFieldValidateOrFn = | [TFormValidateOrFn] extends [StandardSchemaV1] ? TName extends keyof TStandardOut ? StandardSchemaV1Issue[] : undefined : undefined | UnwrapFormValidateOrFnForInner extends infer TFormValidateVal ? TFormValidateVal extends object ? [DeepValue] extends [never] ? undefined : StandardSchemaV1Issue[] : TFormValidateVal extends object ? TName extends keyof TFormValidateVal["fields"] ? TFormValidateVal["fields"][TName] : undefined : undefined : never | [TValidateOrFn] extends [FieldValidateFn] ? ReturnType : [TValidateOrFn] extends [StandardSchemaV1] ? StandardSchemaV1Issue[] : undefined; @@ -18,9 +18,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:121](https://github.com/TanStack ## Type Parameters -• **TParentData** - -• **TName** *extends* [`DeepKeys`](deepkeys.md)\<`TParentData`\> +• **TName** *extends* `string` • **TValidateOrFn** *extends* `undefined` \| `FieldValidateOrFn`\<`any`, `any`, `any`\> diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index 4bd3a1847..2af502b1b 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -119,8 +119,7 @@ type UnwrapFormValidateOrFnForInner< : undefined export type UnwrapFieldValidateOrFn< - TParentData, - TName extends DeepKeys, + TName extends string, TValidateOrFn extends undefined | FieldValidateOrFn, TFormValidateOrFn extends undefined | FormValidateOrFn, > = @@ -202,8 +201,7 @@ type UnwrapFormAsyncValidateOrFnForInner< : undefined export type UnwrapFieldAsyncValidateOrFn< - TParentData, - TName extends DeepKeys, + TName extends string, TValidateOrFn extends undefined | FieldAsyncValidateOrFn, TFormValidateOrFn extends undefined | FormAsyncValidateOrFn, > = @@ -446,31 +444,45 @@ export interface FieldOptions< * An object type representing the required options for the FieldApi class. */ export interface FieldApiOptions< - TParentData, - TName extends DeepKeys, - TData extends DeepValue, - TOnMount extends undefined | FieldValidateOrFn, - TOnChange extends undefined | FieldValidateOrFn, - TOnChangeAsync extends + in out TParentData, + in out TName extends DeepKeys, + in out TData extends DeepValue, + in out TOnMount extends + | undefined + | FieldValidateOrFn, + in out TOnChange extends + | undefined + | FieldValidateOrFn, + in out TOnChangeAsync extends | undefined | FieldAsyncValidateOrFn, - TOnBlur extends undefined | FieldValidateOrFn, - TOnBlurAsync extends + in out TOnBlur extends + | undefined + | FieldValidateOrFn, + in out TOnBlurAsync extends | undefined | FieldAsyncValidateOrFn, - TOnSubmit extends undefined | FieldValidateOrFn, - TOnSubmitAsync extends + in out TOnSubmit extends + | undefined + | FieldValidateOrFn, + in out TOnSubmitAsync extends | undefined | FieldAsyncValidateOrFn, - TFormOnMount extends undefined | FormValidateOrFn, - TFormOnChange extends undefined | FormValidateOrFn, - TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TFormOnBlur extends undefined | FormValidateOrFn, - TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TFormOnSubmit extends undefined | FormValidateOrFn, - TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TFormOnServer extends undefined | FormAsyncValidateOrFn, - TParentSubmitMeta, + in out TFormOnMount extends undefined | FormValidateOrFn, + in out TFormOnChange extends undefined | FormValidateOrFn, + in out TFormOnChangeAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnBlur extends undefined | FormValidateOrFn, + in out TFormOnBlurAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnSubmit extends undefined | FormValidateOrFn, + in out TFormOnSubmitAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnServer extends undefined | FormAsyncValidateOrFn, + in out TParentSubmitMeta, > extends FieldOptions< TParentData, TName, @@ -538,28 +550,13 @@ export type FieldMetaBase< * A map of errors related to the field value. */ errorMap: ValidationErrorMap< - UnwrapFieldValidateOrFn, - UnwrapFieldValidateOrFn, - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnChangeAsync, - TFormOnChangeAsync - >, - UnwrapFieldValidateOrFn, - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnBlurAsync, - TFormOnBlurAsync - >, - UnwrapFieldValidateOrFn, - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnSubmitAsync, - TFormOnSubmitAsync - > + UnwrapFieldValidateOrFn, + UnwrapFieldValidateOrFn, + UnwrapFieldAsyncValidateOrFn, + UnwrapFieldValidateOrFn, + UnwrapFieldAsyncValidateOrFn, + UnwrapFieldValidateOrFn, + UnwrapFieldAsyncValidateOrFn > /** * A flag indicating whether the field is currently being validated. @@ -617,40 +614,25 @@ export type FieldMetaDerived< */ errors: Array< | UnwrapOneLevelOfArray< - UnwrapFieldValidateOrFn + UnwrapFieldValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldValidateOrFn + UnwrapFieldValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnChangeAsync, - TFormOnChangeAsync - > + UnwrapFieldAsyncValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldValidateOrFn + UnwrapFieldValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnBlurAsync, - TFormOnBlurAsync - > + UnwrapFieldAsyncValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldValidateOrFn + UnwrapFieldValidateOrFn > | UnwrapOneLevelOfArray< - UnwrapFieldAsyncValidateOrFn< - TParentData, - TName, - TOnSubmitAsync, - TFormOnSubmitAsync - > + UnwrapFieldAsyncValidateOrFn > > /** @@ -858,31 +840,45 @@ export type AnyFieldApi = FieldApi< * the `new FieldApi` constructor. */ export class FieldApi< - TParentData, - TName extends DeepKeys, - TData extends DeepValue, - TOnMount extends undefined | FieldValidateOrFn, - TOnChange extends undefined | FieldValidateOrFn, - TOnChangeAsync extends + in out TParentData, + in out TName extends DeepKeys, + in out TData extends DeepValue, + in out TOnMount extends + | undefined + | FieldValidateOrFn, + in out TOnChange extends + | undefined + | FieldValidateOrFn, + in out TOnChangeAsync extends | undefined | FieldAsyncValidateOrFn, - TOnBlur extends undefined | FieldValidateOrFn, - TOnBlurAsync extends + in out TOnBlur extends + | undefined + | FieldValidateOrFn, + in out TOnBlurAsync extends | undefined | FieldAsyncValidateOrFn, - TOnSubmit extends undefined | FieldValidateOrFn, - TOnSubmitAsync extends + in out TOnSubmit extends + | undefined + | FieldValidateOrFn, + in out TOnSubmitAsync extends | undefined | FieldAsyncValidateOrFn, - TFormOnMount extends undefined | FormValidateOrFn, - TFormOnChange extends undefined | FormValidateOrFn, - TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TFormOnBlur extends undefined | FormValidateOrFn, - TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TFormOnSubmit extends undefined | FormValidateOrFn, - TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TFormOnServer extends undefined | FormAsyncValidateOrFn, - TParentSubmitMeta, + in out TFormOnMount extends undefined | FormValidateOrFn, + in out TFormOnChange extends undefined | FormValidateOrFn, + in out TFormOnChangeAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnBlur extends undefined | FormValidateOrFn, + in out TFormOnBlurAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnSubmit extends undefined | FormValidateOrFn, + in out TFormOnSubmitAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnServer extends undefined | FormAsyncValidateOrFn, + in out TParentSubmitMeta, > { /** * A reference to the form API instance. @@ -1315,10 +1311,7 @@ export class FieldApi< if (!field.instance) continue const { onChangeListenTo, onBlurListenTo } = field.instance.options.validators || {} - if ( - cause === 'change' && - onChangeListenTo?.includes(this.name as string) - ) { + if (cause === 'change' && onChangeListenTo?.includes(this.name)) { linkedFields.push(field.instance) } if (cause === 'blur' && onBlurListenTo?.includes(this.name as string)) { diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 9c0b7bdb4..8ec9b6d79 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -236,16 +236,16 @@ export interface FormTransform< * An object representing the options for a form. */ export interface FormOptions< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, - TSubmitMeta = never, + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, + in out TSubmitMeta = never, > { /** * Set initial values for your form. @@ -393,15 +393,15 @@ export type FieldInfo = { * An object representing the current state of the form. */ export type BaseFormState< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, > = { /** * The current values of the form fields. @@ -468,15 +468,15 @@ export type BaseFormState< } export type DerivedFormState< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, > = { /** * A boolean indicating if the form is currently validating. @@ -537,38 +537,38 @@ export type DerivedFormState< fieldMeta: Record, AnyFieldMeta> } -export type FormState< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, -> = BaseFormState< - TFormData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TOnServer -> & - DerivedFormState< - TFormData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TOnServer - > +export interface FormState< + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, +> extends BaseFormState< + TFormData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TOnServer + >, + DerivedFormState< + TFormData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TOnServer + > {} export type AnyFormState = FormState< any, @@ -662,16 +662,16 @@ export type AnyFormApi = FormApi< * However, if you need to create a new instance manually, you can do so by calling the `new FormApi` constructor. */ export class FormApi< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, - TSubmitMeta = never, + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, + in out TSubmitMeta = never, > { /** * The options for the form. diff --git a/packages/form-core/src/util-types.ts b/packages/form-core/src/util-types.ts index de966d622..bfd5a368c 100644 --- a/packages/form-core/src/util-types.ts +++ b/packages/form-core/src/util-types.ts @@ -19,132 +19,92 @@ type Try = A1 extends A2 ? A1 : Catch */ export type Narrow = Try> -type ComputeRange< - N extends number, - Result extends Array = [], -> = Result['length'] extends N - ? Result - : ComputeRange -type Index40 = ComputeRange<40>[number] - -// Is this type a tuple? -type IsTuple = T extends readonly any[] & { length: infer Length } - ? Length extends Index40 +type IsAny = 0 extends 1 & T ? true : false + +export type ArrayAccessor = `${TPrefix}[${number}]` + +export type DeepRecordArrayUnion< + T extends ReadonlyArray, + TPrefix extends string, + TAcc, +> = DeepRecordUnion< + T[number], + ArrayAccessor, + TAcc | Record, T[number]> +> + +export type TupleAccessor< + TPrefix extends string, + TKey, +> = `${TPrefix}[${TKey & string}]` + +export type AllTupleKeys = T extends any ? keyof T & `${number}` : never + +export type DeepRecordTupleUnion< + T extends ReadonlyArray, + TPrefix extends string, + TAcc, + TAllKeys extends AllTupleKeys = AllTupleKeys, +> = TAllKeys extends any + ? DeepRecordUnion< + T[TAllKeys], + TupleAccessor, + TAcc | Record, T[TAllKeys]> + > + : never + +export type AllObjectKeys = T extends any + ? keyof T & (string | number) + : never + +export type ObjectAccessor< + TPrefix extends string, + TKey extends string | number, +> = TPrefix extends '' ? `${TKey}` : `${TPrefix}.${TKey}` + +export type DeepRecordObjectUnion< + T, + TPrefix extends string, + TAcc, + TAllKeys extends AllObjectKeys = AllObjectKeys, +> = TAllKeys extends any + ? DeepRecordUnion< + T[TAllKeys], + ObjectAccessor, + TAcc | Record, T[TAllKeys]> + > + : never + +export type DeepRecordUnion = + IsAny extends true ? T - : never + : T extends string | number | boolean | bigint | Date + ? TAcc + : T extends ReadonlyArray + ? number extends T['length'] + ? DeepRecordArrayUnion + : DeepRecordTupleUnion + : T extends object + ? DeepRecordObjectUnion + : TAcc + +export type UnionToIntersection = ( + T extends any ? (param: T) => any : never +) extends (param: infer TI) => any + ? TI : never -// If this type is a tuple, what indices are allowed? -type AllowedIndexes< - Tuple extends ReadonlyArray, - Keys extends number = never, -> = Tuple extends readonly [] - ? Keys - : Tuple extends readonly [infer _, ...infer Tail] - ? AllowedIndexes - : Keys - -type PrefixArrayAccessor = { - [K in keyof T]: `[${number}]${DeepKeys}` -}[number] - -type PrefixTupleAccessor< - T extends any[], - TIndex extends number, - TDepth extends any[], -> = { - [K in TIndex]: `[${K}]` | `[${K}]${DeepKeys}` -}[TIndex] - -type PrefixObjectAccessor = { - [K in keyof T]-?: K extends string | number - ? - | PrefixFromDepth - | `${PrefixFromDepth}${DeepKeys}` - : never -}[keyof T] +export type DeepRecord = UnionToIntersection> /** * The keys of an object or array, deeply nested. */ -export type DeepKeys = TDepth['length'] extends 5 - ? never - : unknown extends T - ? PrefixFromDepth - : T extends readonly any[] & IsTuple - ? PrefixTupleAccessor, TDepth> - : T extends any[] - ? PrefixArrayAccessor - : T extends Date - ? never - : T extends object - ? PrefixObjectAccessor - : T extends string | number | boolean | bigint - ? '' - : never - -type PrefixFromDepth< - T extends string | number, - TDepth extends any[], -> = TDepth['length'] extends 0 ? T : `.${T}` - -// Hack changing Typescript's default get behavior in order to work with union objects -type Get = T extends { [Key in K]: infer V } - ? V - : T extends { [Key in K]?: infer W } - ? W | undefined - : never - -type ApplyNull = null extends T ? null : never -type ApplyUndefined = undefined extends T ? undefined : never +export type DeepKeys = unknown extends T + ? string + : keyof DeepRecord & string /** * Infer the type of a deeply nested property within an object or an array. */ -export type DeepValue< - // The object or array in which we have the property whose type we're trying to infer - TValue, - // A string representing the path of the property we're trying to access - TAccessor, - // Depth for preventing infinite recursion - TDepth extends ReadonlyArray = [], -> = unknown extends TValue // If TValue is any it will recurse forever, this terminates the recursion - ? TValue - : TDepth['length'] extends 10 - ? unknown - : // Check if we're looking for the property in an array - TValue extends ReadonlyArray - ? TAccessor extends `[${infer TBrackets}].${infer TAfter}` - ? /* - Extract the first element from the accessor path (`TBrackets`) - and recursively call `DeepValue` with it - */ - DeepValue< - DeepValue, - TAfter, - [...TDepth, any] - > - : TAccessor extends `[${infer TBrackets}]` - ? DeepValue - : TAccessor extends keyof TValue - ? TValue[TAccessor] - : TValue[TAccessor & number] - : TAccessor extends `${infer TBefore}[${infer TEverythingElse}` - ? DeepValue< - DeepValue, - `[${TEverythingElse}`, - [...TDepth, any] - > - : TAccessor extends `[${infer TBrackets}]` - ? DeepValue - : TAccessor extends `${infer TBefore}.${infer TAfter}` - ? DeepValue< - DeepValue, - TAfter, - [...TDepth, any] - > - : TAccessor extends string - ? - | Get - | (ApplyNull | ApplyUndefined) - : never +export type DeepValue = DeepRecord[TAccessor & + keyof DeepRecord] diff --git a/packages/form-core/tests/FieldApi.test-d.ts b/packages/form-core/tests/FieldApi.test-d.ts index b9d010a94..fcbbc1f60 100644 --- a/packages/form-core/tests/FieldApi.test-d.ts +++ b/packages/form-core/tests/FieldApi.test-d.ts @@ -54,7 +54,7 @@ it('should type required fields in constructor', () => { }) assertType(field.state.value) - assertType<'name'>(field.options.name) + assertType<'name' | 'age'>(field.options.name) assertType(field.getValue()) }) @@ -74,7 +74,7 @@ it('should type value properly for completely partial forms', () => { }) assertType<'test' | undefined>(field.state.value) - assertType<'name'>(field.options.name) + assertType<'name' | 'age'>(field.options.name) assertType<'test' | undefined>(field.getValue()) }) diff --git a/packages/form-core/tests/FormApi.spec.ts b/packages/form-core/tests/FormApi.spec.ts index bc0e0f70a..9852c4eab 100644 --- a/packages/form-core/tests/FormApi.spec.ts +++ b/packages/form-core/tests/FormApi.spec.ts @@ -856,7 +856,6 @@ describe('form api', () => { }, }) field1.mount() - const field2 = new FieldApi({ form, name: 'names[1]', diff --git a/packages/form-core/tests/util-types.test-d.ts b/packages/form-core/tests/util-types.test-d.ts index dc4eaa26e..d738033d3 100644 --- a/packages/form-core/tests/util-types.test-d.ts +++ b/packages/form-core/tests/util-types.test-d.ts @@ -24,6 +24,7 @@ assertType< type ArraySupport = DeepKeys<{ users: User[] }> assertType< | 'users' + | `users[${number}]` | `users[${number}].name` | `users[${number}].id` | `users[${number}].age` diff --git a/packages/react-form/src/types.ts b/packages/react-form/src/types.ts index ddc44a182..1bb935946 100644 --- a/packages/react-form/src/types.ts +++ b/packages/react-form/src/types.ts @@ -3,15 +3,20 @@ import type { DeepValue, FieldApiOptions, FieldAsyncValidateOrFn, + FieldOptions, FieldValidateOrFn, FormAsyncValidateOrFn, FormValidateOrFn, } from '@tanstack/form-core' +interface FieldOptionsMode { + mode?: 'value' | 'array' +} + /** * The field options. */ -export type UseFieldOptions< +export interface UseFieldOptions< TParentData, TName extends DeepKeys, TData extends DeepValue, @@ -37,26 +42,56 @@ export type UseFieldOptions< TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, TFormOnServer extends undefined | FormAsyncValidateOrFn, TSubmitMeta, -> = FieldApiOptions< +> extends FieldApiOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TSubmitMeta + >, + FieldOptionsMode {} + +export interface UseFieldOptionsBound< TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TSubmitMeta -> & { - mode?: 'value' | 'array' -} + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, +> extends FieldOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync + >, + FieldOptionsMode {} diff --git a/packages/react-form/src/useField.tsx b/packages/react-form/src/useField.tsx index 1b52980ae..e3e35e977 100644 --- a/packages/react-form/src/useField.tsx +++ b/packages/react-form/src/useField.tsx @@ -11,7 +11,7 @@ import type { FormValidateOrFn, } from '@tanstack/form-core' import type { FunctionComponent, ReactNode } from 'react' -import type { UseFieldOptions } from './types' +import type { UseFieldOptions, UseFieldOptionsBound } from './types' interface ReactFieldApi< TParentData, @@ -75,29 +75,17 @@ export type UseField< | undefined | FieldAsyncValidateOrFn, >( - opts: Omit< - UseFieldOptions< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TPatentSubmitMeta - >, - 'form' + opts: UseFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync >, ) => FieldApi< TParentData, @@ -227,7 +215,7 @@ export function useField< /** * @param children A render function that takes a field API instance and returns a React element. */ -type FieldComponentProps< +interface FieldComponentProps< TParentData, TName extends DeepKeys, TData extends DeepValue, @@ -254,7 +242,27 @@ type FieldComponentProps< TFormOnServer extends undefined | FormAsyncValidateOrFn, TPatentSubmitMeta, ExtendedApi = {}, -> = { +> extends UseFieldOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TPatentSubmitMeta + > { children: ( fieldApi: FieldApi< TParentData, @@ -279,33 +287,25 @@ type FieldComponentProps< > & ExtendedApi, ) => ReactNode -} & UseFieldOptions< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TPatentSubmitMeta -> +} -/** - * A type alias representing a field component for a specific form data type. - */ -export type FieldComponent< +interface FieldComponentBoundProps< TParentData, + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, TFormOnMount extends undefined | FormValidateOrFn, TFormOnChange extends undefined | FormValidateOrFn, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn, @@ -316,6 +316,65 @@ export type FieldComponent< TFormOnServer extends undefined | FormAsyncValidateOrFn, TPatentSubmitMeta, ExtendedApi = {}, +> extends UseFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync + > { + children: ( + fieldApi: FieldApi< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TPatentSubmitMeta + > & + ExtendedApi, + ) => ReactNode +} + +/** + * A type alias representing a field component for a specific form data type. + */ +export type FieldComponent< + in out TParentData, + in out TFormOnMount extends undefined | FormValidateOrFn, + in out TFormOnChange extends undefined | FormValidateOrFn, + in out TFormOnChangeAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnBlur extends undefined | FormValidateOrFn, + in out TFormOnBlurAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnSubmit extends undefined | FormValidateOrFn, + in out TFormOnSubmitAsync extends + | undefined + | FormAsyncValidateOrFn, + in out TFormOnServer extends undefined | FormAsyncValidateOrFn, + in out TPatentSubmitMeta, + in out ExtendedApi = {}, > = < const TName extends DeepKeys, TData extends DeepValue, @@ -335,30 +394,27 @@ export type FieldComponent< >({ children, ...fieldOptions -}: Omit< - FieldComponentProps< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TPatentSubmitMeta, - ExtendedApi - >, - 'form' +}: FieldComponentBoundProps< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TPatentSubmitMeta, + ExtendedApi >) => ReactNode /** diff --git a/packages/react-form/src/useForm.tsx b/packages/react-form/src/useForm.tsx index 2831190d1..729064aba 100644 --- a/packages/react-form/src/useForm.tsx +++ b/packages/react-form/src/useForm.tsx @@ -19,16 +19,16 @@ import type { NoInfer } from '@tanstack/react-store' * Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm` */ export interface ReactFormApi< - TFormData, - TOnMount extends undefined | FormValidateOrFn, - TOnChange extends undefined | FormValidateOrFn, - TOnChangeAsync extends undefined | FormAsyncValidateOrFn, - TOnBlur extends undefined | FormValidateOrFn, - TOnBlurAsync extends undefined | FormAsyncValidateOrFn, - TOnSubmit extends undefined | FormValidateOrFn, - TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, - TOnServer extends undefined | FormAsyncValidateOrFn, - TSubmitMeta, + in out TFormData, + in out TOnMount extends undefined | FormValidateOrFn, + in out TOnChange extends undefined | FormValidateOrFn, + in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn, + in out TOnBlur extends undefined | FormValidateOrFn, + in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn, + in out TOnSubmit extends undefined | FormValidateOrFn, + in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + in out TOnServer extends undefined | FormAsyncValidateOrFn, + in out TSubmitMeta, > { /** * A React component to render form fields. With this, you can render and manage individual form fields. diff --git a/packages/solid-form/src/createField.tsx b/packages/solid-form/src/createField.tsx index 7c57e2738..9113720de 100644 --- a/packages/solid-form/src/createField.tsx +++ b/packages/solid-form/src/createField.tsx @@ -18,7 +18,7 @@ import type { } from '@tanstack/form-core' import type { JSXElement } from 'solid-js' -import type { CreateFieldOptions } from './types' +import type { CreateFieldOptions, CreateFieldOptionsBound } from './types' interface SolidFieldApi< TParentData, @@ -73,31 +73,18 @@ export type CreateField< TOnSubmitAsync extends | undefined | FieldAsyncValidateOrFn, - TSubmitMeta, >( - opts: () => { name: Narrow } & Omit< - CreateFieldOptions< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TSubmitMeta - >, - 'form' + opts: () => { name: Narrow } & CreateFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync >, ) => () => FieldApi< TParentData, @@ -347,7 +334,7 @@ export function createField< >(extendedApi as never) } -type FieldComponentProps< +interface FieldComponentBoundProps< TParentData, TName extends DeepKeys, TData extends DeepValue, @@ -373,7 +360,18 @@ type FieldComponentProps< TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, TFormOnServer extends undefined | FormAsyncValidateOrFn, TParentSubmitMeta, -> = { +> extends CreateFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync + > { children: ( fieldApi: () => FieldApi< TParentData, @@ -397,30 +395,7 @@ type FieldComponentProps< TParentSubmitMeta >, ) => JSXElement -} & Omit< - CreateFieldOptions< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TParentSubmitMeta - >, - 'form' -> +} export type FieldComponent< TParentData, @@ -452,8 +427,55 @@ export type FieldComponent< >({ children, ...fieldOptions -}: Omit< - FieldComponentProps< +}: FieldComponentBoundProps< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TParentSubmitMeta +>) => JSXElement + +interface FieldComponentProps< + TParentData, + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, + TFormOnMount extends undefined | FormValidateOrFn, + TFormOnChange extends undefined | FormValidateOrFn, + TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn, + TFormOnBlur extends undefined | FormValidateOrFn, + TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn, + TFormOnSubmit extends undefined | FormValidateOrFn, + TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, + TFormOnServer extends undefined | FormAsyncValidateOrFn, + TParentSubmitMeta, +> extends CreateFieldOptions< TParentData, TName, TData, @@ -473,9 +495,31 @@ export type FieldComponent< TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta - >, - 'form' ->) => JSXElement + > { + children: ( + fieldApi: () => FieldApi< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TParentSubmitMeta + >, + ) => JSXElement +} export function Field< TParentData, @@ -504,31 +548,7 @@ export function Field< TFormOnServer extends undefined | FormAsyncValidateOrFn, TParentSubmitMeta, >( - props: { - children: ( - fieldApi: () => FieldApi< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TParentSubmitMeta - >, - ) => JSXElement - } & CreateFieldOptions< + props: FieldComponentProps< TParentData, TName, TData, diff --git a/packages/solid-form/src/types.ts b/packages/solid-form/src/types.ts index 3ca6b70f8..e5dd2126a 100644 --- a/packages/solid-form/src/types.ts +++ b/packages/solid-form/src/types.ts @@ -3,12 +3,17 @@ import type { DeepValue, FieldApiOptions, FieldAsyncValidateOrFn, + FieldOptions, FieldValidateOrFn, FormAsyncValidateOrFn, FormValidateOrFn, } from '@tanstack/form-core' -export type CreateFieldOptions< +interface FieldOptionsMode { + mode?: 'value' | 'array' +} + +export interface CreateFieldOptions< TParentData, TName extends DeepKeys, TData extends DeepValue, @@ -34,26 +39,56 @@ export type CreateFieldOptions< TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, TFormOnServer extends undefined | FormAsyncValidateOrFn, TSubmitMeta, -> = FieldApiOptions< +> extends FieldApiOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TSubmitMeta + >, + FieldOptionsMode {} + +export interface CreateFieldOptionsBound< TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TSubmitMeta -> & { - mode?: 'value' | 'array' -} + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, +> extends FieldOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync + >, + FieldOptionsMode {} diff --git a/packages/vue-form/src/types.ts b/packages/vue-form/src/types.ts index 199c807da..c4eb1a62d 100644 --- a/packages/vue-form/src/types.ts +++ b/packages/vue-form/src/types.ts @@ -3,12 +3,17 @@ import type { DeepValue, FieldApiOptions, FieldAsyncValidateOrFn, + FieldOptions, FieldValidateOrFn, FormAsyncValidateOrFn, FormValidateOrFn, } from '@tanstack/form-core' -export type UseFieldOptions< +interface FieldOptionsMode { + mode?: 'value' | 'array' +} + +export interface UseFieldOptions< TParentData, TName extends DeepKeys, TData extends DeepValue, @@ -34,26 +39,56 @@ export type UseFieldOptions< TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn, TFormOnServer extends undefined | FormAsyncValidateOrFn, TSubmitMeta, -> = FieldApiOptions< +> extends FieldApiOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync, + TFormOnMount, + TFormOnChange, + TFormOnChangeAsync, + TFormOnBlur, + TFormOnBlurAsync, + TFormOnSubmit, + TFormOnSubmitAsync, + TFormOnServer, + TSubmitMeta + >, + FieldOptionsMode {} + +export interface UseFieldOptionsBound< TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TSubmitMeta -> & { - mode?: 'value' | 'array' -} + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, +> extends FieldOptions< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync + >, + FieldOptionsMode {} diff --git a/packages/vue-form/src/useField.tsx b/packages/vue-form/src/useField.tsx index e778fa0b7..c63631431 100644 --- a/packages/vue-form/src/useField.tsx +++ b/packages/vue-form/src/useField.tsx @@ -19,7 +19,7 @@ import type { SetupContext, SlotsType, } from 'vue' -import type { UseFieldOptions } from './types' +import type { UseFieldOptions, UseFieldOptionsBound } from './types' export type FieldComponent< TParentData, @@ -51,56 +51,32 @@ export type FieldComponent< | undefined | FieldAsyncValidateOrFn, >( - props: Omit< - FieldComponentProps< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TParentSubmitMeta - >, - 'form' + props: FieldComponentBoundProps< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync > & EmitsToProps & PublicProps, ) => CreateComponentPublicInstanceWithMixins< - Omit< - FieldComponentProps< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TParentSubmitMeta - >, - 'form' + FieldComponentBoundProps< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync >, {}, {}, @@ -215,29 +191,17 @@ export type UseField< | undefined | FieldAsyncValidateOrFn, >( - opts: Omit< - UseFieldOptions< - TParentData, - TName, - TData, - TOnMount, - TOnChange, - TOnChangeAsync, - TOnBlur, - TOnBlurAsync, - TOnSubmit, - TOnSubmitAsync, - TFormOnMount, - TFormOnChange, - TFormOnChangeAsync, - TFormOnBlur, - TFormOnBlurAsync, - TFormOnSubmit, - TFormOnSubmitAsync, - TFormOnServer, - TParentSubmitMeta - >, - 'form' + opts: UseFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync >, ) => { api: FieldApi< @@ -445,6 +409,36 @@ export type FieldComponentProps< TParentSubmitMeta > +export type FieldComponentBoundProps< + TParentData, + TName extends DeepKeys, + TData extends DeepValue, + TOnMount extends undefined | FieldValidateOrFn, + TOnChange extends undefined | FieldValidateOrFn, + TOnChangeAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnBlur extends undefined | FieldValidateOrFn, + TOnBlurAsync extends + | undefined + | FieldAsyncValidateOrFn, + TOnSubmit extends undefined | FieldValidateOrFn, + TOnSubmitAsync extends + | undefined + | FieldAsyncValidateOrFn, +> = UseFieldOptionsBound< + TParentData, + TName, + TData, + TOnMount, + TOnChange, + TOnChangeAsync, + TOnBlur, + TOnBlurAsync, + TOnSubmit, + TOnSubmitAsync +> + export const Field = defineComponent( < TParentData,