-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.0.1] Typehinting useForm with interface gives error. #2188
Comments
Bisected to 93af171, which is indeed part of #2060. The Svelte adapter has the same issue, where as the Vue 3 one does not as it still uses object. Short term fix, define import { useForm } from '@inertiajs/react'
type ConnectionData = {
url: string | null
host: string
port: string
}
declare const connection: Partial<ConnectionData> | undefined | null
const form = useForm<ConnectionData>({
url: connection?.url ?? '',
host: connection?.host ?? '',
port: connection?.port ?? '',
}) |
The commit #2060 is also giving me issues because I cannot include typed Dayjs objects from date pickers to then transform for submission.
Considering that this causes issues for any other objects too, I believe this change should be reverted. |
I had to convert my interfaces to type to be able to pass tsc. |
I have the same problem with Vue 3 and inertia 2.0.3 |
Adding interface ConnectionData {
url: string | null;
host: string;
port: string;
[key: string]: any
} On |
The solution of @sebastiaanluca works because allow to introduce a dynamic property for the interface, however is not totally suitable because now is easy to assign values to wrong parameters without any warning from the typescript linter. |
Version:
@inertiajs/react
version: 2.0.1Describe the problem:
Using an interface to typehint
useForm
throws a Typescript error in version 2.0.1, whereas in 2.0.0 it worked.Steps to reproduce:
useForm
for the type parameter.Example:
Gives the following error:
TS2344: Type
ConnectionData
does not satisfy the constraintFormDataType
. Index signature for type string is missing in typeConnectionData
I believe it is related to the changes made in #2060
The text was updated successfully, but these errors were encountered: