Skip to content

Commit 2392355

Browse files
committed
chore: initial work to add composition api to svelte
1 parent e7b0dcf commit 2392355

File tree

2 files changed

+457
-2
lines changed

2 files changed

+457
-2
lines changed

packages/svelte-form/src/createForm.svelte.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,53 @@ export interface SvelteFormApi<
179179
WithoutFunction<Component>
180180
}
181181

182+
183+
/**
184+
* An extended version of the `FormApi` class that includes Svelte-specific functionalities from `SvelteFormApi`
185+
*/
186+
export type SvelteFormExtendedApi<
187+
TFormData,
188+
TOnMount extends undefined | FormValidateOrFn<TFormData>,
189+
TOnChange extends undefined | FormValidateOrFn<TFormData>,
190+
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
191+
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
192+
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
193+
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
194+
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
195+
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
196+
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
197+
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
198+
TSubmitMeta,
199+
> = FormApi<
200+
TFormData,
201+
TOnMount,
202+
TOnChange,
203+
TOnChangeAsync,
204+
TOnBlur,
205+
TOnBlurAsync,
206+
TOnSubmit,
207+
TOnSubmitAsync,
208+
TOnDynamic,
209+
TOnDynamicAsync,
210+
TOnServer,
211+
TSubmitMeta
212+
> &
213+
SvelteFormApi<
214+
TFormData,
215+
TOnMount,
216+
TOnChange,
217+
TOnChangeAsync,
218+
TOnBlur,
219+
TOnBlurAsync,
220+
TOnSubmit,
221+
TOnSubmitAsync,
222+
TOnDynamic,
223+
TOnDynamicAsync,
224+
TOnServer,
225+
TSubmitMeta
226+
>
227+
228+
182229
export function createForm<
183230
TParentData,
184231
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
@@ -241,10 +288,10 @@ export function createForm<
241288

242289
// @ts-expect-error constructor definition exists only on a type level
243290
extendedApi.Field = (internal, props) =>
244-
Field(internal, { ...props, form: api })
291+
Field(internal, { ...props, form: api as never } as never)
245292
extendedApi.createField = (props) =>
246293
createField(() => {
247-
return { ...props(), form: api }
294+
return { ...props(), form: api } as never
248295
}) as never // Type cast because else "Error: Type instantiation is excessively deep and possibly infinite."
249296
extendedApi.useStore = (selector) => useStore(api.store, selector)
250297
// @ts-expect-error constructor definition exists only on a type level

0 commit comments

Comments
 (0)