diff --git a/packages/react-inertia/src/index.ts b/packages/react-inertia/src/index.ts index d83258e..9eacfab 100644 --- a/packages/react-inertia/src/index.ts +++ b/packages/react-inertia/src/index.ts @@ -2,10 +2,11 @@ import { Config, NamedInputEvent, RequestMethod, SimpleValidationErrors, toSimpl import { useForm as usePrecognitiveForm, client } from 'laravel-precognition-react' import { useForm as useInertiaForm } from '@inertiajs/react' import { useRef } from 'react' +import { Form } from './types' export { client } -export const useForm = >(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config: ValidationConfig = {}): any => { +export const useForm = >(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config: ValidationConfig = {}): Form => { const booted = useRef(false) /** diff --git a/packages/react-inertia/src/types.ts b/packages/react-inertia/src/types.ts new file mode 100644 index 0000000..4235c27 --- /dev/null +++ b/packages/react-inertia/src/types.ts @@ -0,0 +1,19 @@ +import { NamedInputEvent, RequestMethod, SimpleValidationErrors, ValidationConfig, ValidationErrors } from 'laravel-precognition' +import { Form as PrecognitiveForm } from 'laravel-precognition-react/dist/types' +import { InertiaFormProps } from '@inertiajs/react' +import { VisitOptions } from '@inertiajs/core' + +type RedefinedProperties = 'setErrors' | 'touch' | 'forgetError' | 'setValidationTimeout' | 'submit' | 'reset' | 'validateFiles' | 'setData' | 'validate' + +export type Form> = Omit, RedefinedProperties> & InertiaFormProps & { + setErrors(errors: SimpleValidationErrors | ValidationErrors): Data & Form, + touch(name: Array | string | NamedInputEvent): Data & Form, + forgetError(string: keyof Data | NamedInputEvent): Data & Form, + setValidationTimeout(duration: number): Data & Form, + submit(config?: Partial): void, + submit(method: RequestMethod, url: string, options?: Partial): void, + reset(...keys: (keyof Partial)[]): Data & Form, + validateFiles(): Data & Form, + setData(data: Record): Data & Form, + validate(name?: (keyof Data | NamedInputEvent) | ValidationConfig, config?: ValidationConfig): Data & Form, +}