import type { SvelteComponentDev } from "svelte/internal"; export interface DynamicSvelteComponent< T extends typeof SvelteComponentDev = typeof SvelteComponentDev > { component: T; } export const dynamicComponent = (component: T) => < U extends NonNullable[0]["props"]>, V extends string = never >( props: Omit, lazyProps: { [Property in keyof Pick]: () => Pick[Property] } ): DynamicSvelteComponent & U => { 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 & U; };