laravel / precognition

Anticipate the outcome of a future HTTP request.
https://laravel.com/docs/precognition
MIT License
132 stars 32 forks source link

Vue + Inertia useForm now uses an object compatible signature #64

Closed juanparati closed 8 months ago

juanparati commented 8 months ago

This is the solution to https://github.com/laravel/precognition/issues/63.

The signature for "useForm" (Vue + InertiaJS package) was changed to object instead of Record<string, unknown> so it's going to be compatible with the native InertiaJS "useForm" that accepts also an object (type FormDataType = object).

"usePrecognitiveForm" type was hydrated as Record<string, unknown> so it should not break the compatibility.

Record<string, unknown> it's basically an object, so everything should work as expected.

I did a test with with Typescript 5.3.3.

driesvints commented 8 months ago

@juanparati tests fail here

juanparati commented 8 months ago

@driesvints : I had to suppress incompatible type errors for inertiaClearErrors and inertiaReset. I could not change the parameters signature for the "reset" method because precognitiveForm.setErrors uses Record<string, unknown> and it's a main precognition method. If I change the setErrors signature for the method I will break other packages.

I will see if I can come in the following days with a more elegant solution that can also fix the issue with the useForm return type and I will submit a new pull request.