-
Notifications
You must be signed in to change notification settings - Fork 59
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
<Form {context}> produces type error with TypeScript #148
Comments
I think you are mixing two different ways of creating the form. When you use the When you just use a plain HTML |
Okay, thanks. I can make the type errors go away by doing that, but it makes too many type errors go away. Notice that I do not get a type error in the following code because the types of the Notice that when I use Besides, the type declaration indicates that the form context is supposed to be a valid input to the export type FormProps<Inf = Record<string, unknown>> = {
context?: FormState;
initialValues?: Inf;
onSubmit?: ((values: Inf) => any) | ((values: Inf) => Promise<any>);
validate?: (values: Inf) => any | undefined;
validationSchema?: ObjectSchema<any>;
} & svelte.JSX.HTMLAttributes<HTMLFormElement>;
/* ... */
declare class Form extends SvelteComponentTyped<
FormProps,
Record<string, unknown>,
{
default: FormState;
}
> {} |
Any update on this issue? |
Summary
With TypeScript, I would like to both use the helper components and have the values passed to my onSubmit handler be typed. In order to do this, I have to call createForm (to get type inference) and pass the resulting context to the Form helper. But when I do this I get a type error saying that my FormState type "is not assignable to type 'FormState<Record<string, any>>".
Example
The following working code produces the error:
Here is the type error:
Workaround
I am using the following workaround for now, declaring the context to have type 'any':
Possible fixes
I suspect that changing
Record<string, any>
to{[key: string]: any}
inindex.d.ts
might correct the problem.The text was updated successfully, but these errors were encountered: