2021-04-08 16:29:28 +02:00
|
|
|
import type { SvelteComponentDev } from "svelte/internal";
|
|
|
|
|
|
|
|
export interface DynamicSvelteComponent<
|
|
|
|
T extends typeof SvelteComponentDev = typeof SvelteComponentDev
|
|
|
|
> {
|
|
|
|
component: T;
|
|
|
|
}
|
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
export const dynamicComponent = <
|
|
|
|
Comp extends typeof SvelteComponentDev,
|
|
|
|
DefaultProps = NonNullable<ConstructorParameters<Comp>[0]["props"]>
|
2021-04-08 16:29:28 +02:00
|
|
|
>(
|
2021-04-09 18:42:41 +02:00
|
|
|
component: Comp
|
|
|
|
) => <Props = DefaultProps>(props: Props): DynamicSvelteComponent<Comp> & Props => {
|
|
|
|
return { component, ...props };
|
2021-04-08 16:29:28 +02:00
|
|
|
};
|