-
Notifications
You must be signed in to change notification settings - Fork 58
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 array doesn't work with Typescript #154
Comments
Same experience on using a Currently my workaround is to explicitly cast: $: fruitErrors = $errors.fruits as unknown as string[]; Looks like this comes from https://github.com/tjinauyeung/svelte-forms-lib/blob/master/lib/index.d.ts#L34 Should svelte-forms-lib/lib/create-form.js Lines 142 to 164 in 7df1b1d
I'm not TypeScript definitions guru, but I assume it would be possible to refine |
Another solution to this is to cast is before assigning it to .import type { FormProps } from 'svelte-forms-lib';
import { Form, Field } from 'svelte-forms-lib';
// Specify your own form field type, to you have safe typing
type FormFields = {
email: string
username: string
password: string
}
const formProps: FormProps<FormFields> = {
initialValues: {}
.... etc
}
// Cast formProps to the type <Form> expects
const props = formProps as FormProps; // ← ← ← Then assign <Form {...props}>
<!-- form contents -->
</Form> But this behavior does seem like a bug. |
Summary
Steps to reproduce
Copy paste the form array code example here and change the script lang for
ts
Example Project
CodeSandox
What is the current bug behavior?
There are some typescript errors :
What is the expected correct behavior?
No typescript error anymore
Relevant logs and/or screenshots
The text was updated successfully, but these errors were encountered: