Skip to content

Commit f96f154

Browse files
author
Larry Botha
authored
Merge pull request tjinauyeung#98 from pixelmund/typingsv2
2 parents f146eff + 87451f3 commit f96f154

File tree

2 files changed

+965
-37
lines changed

2 files changed

+965
-37
lines changed

lib/index.d.ts

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
1+
/// <reference path="svelte-jsx.d.ts" />
12
import type {SvelteComponentTyped} from 'svelte';
23
import type {Readable, Writable} from 'svelte/store';
34
import type {ObjectSchema} from 'yup';
45

5-
/**
6-
* Unfortunately svelte currently does not support generics in components so we export it to use it in scripts like this
7-
*
8-
* const formProps: FormProps = {
9-
* intitialValues: {...},
10-
* onSubmit: values => {...} -> values will be inffered from initialValues
11-
* }
12-
*
13-
* */
14-
export type FormProps<Inf = Record<string, unknown>> = {
6+
export type FormProps<Inf = Record<string, any>> = {
157
initialValues: Inf;
168
onSubmit: ((values: Inf) => any) | ((values: Inf) => Promise<any>);
179
validate?: (values: Inf) => any | undefined;
1810
validationSchema?: ObjectSchema<any>;
19-
}
11+
} & svelte.JSX.HTMLAttributes<HTMLFormElement>;
2012

2113
type FieldProps = {
2214
name: string;
2315
type?: string;
2416
value?: string;
25-
};
17+
} & svelte.JSX.HTMLProps<HTMLInputElement>;
2618

2719
type SelectProps = {
2820
name: string;
29-
class?: string;
30-
value?: string;
31-
};
21+
} & svelte.JSX.HTMLProps<HTMLSelectElement>;
3222

3323
type ErrorProps = {
3424
name: string;
35-
class?: string;
36-
};
25+
} & svelte.JSX.HTMLProps<HTMLDivElement>;
3726

3827
type TextareaProps = {
3928
name: string;
40-
class?: string;
41-
cols?: number;
42-
rows?: number;
43-
};
29+
} & svelte.JSX.HTMLProps<HTMLTextAreaElement>;
4430

45-
type FormState<Inf = Record<string, unknown>> = {
31+
type FormState<Inf = Record<string, any>> = {
4632
form: Writable<Inf>;
4733
errors: Writable<Record<keyof Inf, string>>;
4834
touched: Writable<Record<keyof Inf, boolean>>;
@@ -71,30 +57,18 @@ type FormState<Inf = Record<string, unknown>> = {
7157
handleSubmit: () => any;
7258
};
7359

74-
declare function createForm<Inf = Record<string, unknown>>(formProps: {
60+
declare function createForm<Inf = Record<string, any>>(formProps: {
7561
initialValues: Inf;
7662
onSubmit: (values: Inf) => any | Promise<any>;
7763
validate?: (values: Inf) => any | undefined;
7864
validationSchema?: ObjectSchema<any>;
7965
}): FormState<Inf>;
8066

8167
declare class Form extends SvelteComponentTyped<
82-
FormProps & {
83-
class?: string;
84-
},
68+
FormProps,
8569
{},
8670
{
87-
default: Pick<
88-
FormState,
89-
| 'errors'
90-
| 'touched'
91-
| 'updateField'
92-
| 'updateTouched'
93-
| 'handleChange'
94-
| 'handleSubmit'
95-
| 'form'
96-
| 'state'
97-
>;
71+
default: FormState;
9872
}
9973
> {}
10074

0 commit comments

Comments
 (0)