From c587c73e75e3ab8d311dd46539b39bb630b753a3 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Wed, 11 Dec 2024 09:39:35 -0600 Subject: [PATCH 1/2] Added types.ts for react-inertia. --- packages/react-inertia/src/types.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/react-inertia/src/types.ts 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, +} From 6bcec1af76d91fe819d274c26f3592a7b790c33b Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Wed, 11 Dec 2024 09:42:35 -0600 Subject: [PATCH 2/2] Update useForm return type. --- packages/react-inertia/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) /**