Skip to content

Commit 3f85932

Browse files
committed
refactor: refactored types added support for let:errors etc
1 parent b32737f commit 3f85932

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

lib/index.d.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import type {ObjectSchema} from 'yup';
1212
*
1313
* */
1414
export type FormProps<Inf = Record<string, unknown>> = {
15-
class?: string;
1615
initialValues: Inf;
1716
onSubmit: ((values: Inf) => any) | ((values: Inf) => Promise<any>);
1817
validate?: (values: Inf) => any | undefined;
1918
validationSchema?: ObjectSchema<any>;
20-
};
19+
}
2120

2221
type FieldProps = {
2322
name: string;
@@ -43,12 +42,7 @@ type TextareaProps = {
4342
rows?: number;
4443
};
4544

46-
declare function createForm<Inf = Record<string, unknown>>(formProps: {
47-
initialValues: Inf;
48-
onSubmit: (values: Inf) => any | Promise<any>;
49-
validate?: (values: Inf) => any | undefined;
50-
validationSchema?: ObjectSchema<any>;
51-
}): {
45+
type FormState<Inf = Record<string, unknown>> = {
5246
form: Writable<Inf>;
5347
errors: Writable<Record<keyof Inf, string>>;
5448
touched: Writable<Record<keyof Inf, boolean>>;
@@ -77,12 +71,31 @@ declare function createForm<Inf = Record<string, unknown>>(formProps: {
7771
handleSubmit: () => any;
7872
};
7973

74+
declare function createForm<Inf = Record<string, unknown>>(formProps: {
75+
initialValues: Inf;
76+
onSubmit: (values: Inf) => any | Promise<any>;
77+
validate?: (values: Inf) => any | undefined;
78+
validationSchema?: ObjectSchema<any>;
79+
}): FormState<Inf>;
80+
8081
declare class Form extends SvelteComponentTyped<
8182
FormProps & {
8283
class?: string;
8384
},
8485
{},
85-
{default: any}
86+
{
87+
default: Pick<
88+
FormState,
89+
| 'errors'
90+
| 'touched'
91+
| 'updateField'
92+
| 'updateTouched'
93+
| 'handleChange'
94+
| 'handleSubmit'
95+
| 'form'
96+
| 'state'
97+
>;
98+
}
8699
> {}
87100

88101
declare class Field extends SvelteComponentTyped<FieldProps, {}, {}> {}

0 commit comments

Comments
 (0)