import type { SvelteComponentDev } from "svelte/internal"; export interface DynamicSvelteComponent< T extends typeof SvelteComponentDev = typeof SvelteComponentDev > { component: T; } export const dynamicComponent = ( component: Comp ) => < Props extends NonNullable[0]["props"]>, Lazy extends string = never >( props: Omit, lazyProps: { [Property in keyof Pick]: () => Pick[Property]; } ): DynamicSvelteComponent & Props => { const dynamicComponent = { component, ...props }; for (const property in lazyProps) { const get = lazyProps[property]; const propertyDescriptor: TypedPropertyDescriptor< Pick[Extract, string>] > = { get, enumerable: true }; Object.defineProperty(dynamicComponent, property, propertyDescriptor); } return dynamicComponent as DynamicSvelteComponent & Props; };