-
-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Is your feature request related to a problem? Please describe.
To have generic components it's sometimes neccessary to pass down union types where only an intersection of the type is equal.
Demo:
https://www.sveltelab.dev/y7gmqoire0bl3u4?files=.%2Fsrc%2Flib%2Funion.svelte
Union component:
export let superForm:
| SuperForm<Infer<typeof eventSchema>>
| SuperForm<Infer<typeof admissionSchema>>
| SuperForm<Infer<typeof eventTemplateSchema>>;
Schemas:
export const eventSchema = z.object({
name: z.string()
});
export const eventTemplateSchema = z.object({
name: z.string(),
id: z.string()
});
export const admissionSchema = z.object({
name: z.string()
});
Generic input component
export let superForm: SuperForm<T> | undefined = undefined;
But TypeScript complains if the schema types differ even slightly from each other.
Type 'SuperForm<{ name: string; }> | SuperForm<{ name: string; }> | SuperForm<{ name: string; id: string; }>' is not assignable to type 'SuperForm<{ name: string; }> | undefined'.
Type 'SuperForm<{ name: string; id: string; }>' is not assignable to type 'SuperForm<{ name: string; }>'.
The types of 'options.onUpdate' are incompatible between these types.
Type '((event: { form: SuperValidated<{ name: string; id: string; }, any, { name: string; id: string; }>; formEl: HTMLFormElement; formElement: HTMLFormElement; cancel: () => void; result: Required<...>; }) => unknown) | undefined' is not assignable to type '((event: { form: SuperValidated<{ name: string; }, any, { name: string; }>; formEl: HTMLFormElement; formElement: HTMLFormElement; cancel: () => void; result: Required<...>; }) => unknown) | undefined'.
Type '(event: { form: SuperValidated<{ name: string; id: string; }, any, { name: string; id: string; }>; formEl: HTMLFormElement; formElement: HTMLFormElement; cancel: () => void; result: Required<...>; }) => unknown' is not assignable to type '(event: { form: SuperValidated<{ name: string; }, any, { name: string; }>; formEl: HTMLFormElement; formElement: HTMLFormElement; cancel: () => void; result: Required<...>; }) => unknown'.
Describe the solution you'd like
It would be helpful to make the generics work with unions somehow
fehnomenal
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request