11import { ComputedRef , Ref } from '@vue/runtime-core'
22import { RegisterOptions , RegisterReturn } from './register'
33
4+ type ComputableUnion < T > = T | Ref < T > | ComputedRef < T >
5+
6+ type ConfigType < T > = Partial < Record < keyof T , RegisterOptions > >
7+
8+ type PossiblePromise < T > = T | Promise < T >
9+
410export interface FormState < T > {
511 isDirty : boolean
612 isTouched : boolean
@@ -17,11 +23,15 @@ export type HandleSubmitErrorFn<T> = (errors: FormState<T>['errors']) => void
1723export type HandleSubmitSuccessFn < T > = ( values : Record < keyof T , any > ) => void
1824
1925export type Build < T extends Record < string , any > = Record < string , any > > = <
20- TBuild extends Partial < Record < keyof T , RegisterOptions > > ,
26+ TBuild extends Partial < T > ,
2127> (
22- configuration : TBuild | Ref < TBuild > | ComputedRef < TBuild >
23- ) => ComputedRef < Record < keyof TBuild , Readonly < RegisterReturn < TBuild > > > >
24-
28+ configuration : ComputableUnion < ConfigType < TBuild > >
29+ ) => ComputedRef <
30+ Record <
31+ keyof TBuild ,
32+ Readonly < RegisterReturn < Partial < Record < keyof TBuild , RegisterOptions > > > >
33+ >
34+ >
2535export interface PartialReturn < T > {
2636 /** Current form values */
2737 values : Partial < T >
@@ -79,23 +89,23 @@ export interface FormHandlerReturn<T extends Record<string, any>>
7989
8090export type Interceptor < T > = (
8191 _ : InterceptorParams < T >
82- ) => Promise < boolean > | boolean
92+ ) => PossiblePromise < boolean >
8393
8494export type SubmitValidation = (
8595 values : Record < string , any >
86- ) => Promise < boolean > | boolean
96+ ) => PossiblePromise < boolean >
8797
8898export type InjectionKey = string | Symbol
8999
90100export interface FormHandlerParams < TForm , TInitial > {
91101 /** Values to initialize the form */
92- initialValues ?: TInitial | Ref < TInitial > | ComputedRef < TInitial >
102+ initialValues ?: ComputableUnion < TInitial >
93103
94104 /** Field change interceptor */
95105 interceptor ?: Interceptor < TForm >
96106
97107 /** Validation function to execute before submitting (when using this individual validations are invalidated) */
98- validate ?: ( values : Partial < TForm > ) => Promise < boolean > | boolean
108+ validate ?: ( values : Partial < TForm > ) => PossiblePromise < boolean >
99109
100110 /** Validation behavior options */
101111 validationMode ?: 'onChange' | 'onBlur' | 'onSubmit' | 'always'
0 commit comments