Type Alias ComponentType<Component>

ComponentType<Component>: (new (options: ComponentConstructorOptions<Component extends SvelteComponent<infer Props>
    ? Props
    : Record<string, any>>) => Component) & {
    element?: typeof HTMLElement;
}

Convenience type to get the type of a Svelte component. Useful for example in combination with dynamic components using <svelte:component>.

Example:

<script lang="ts">
import type { ComponentType, SvelteComponent } from 'svelte';
import Component1 from './Component1.svelte';
import Component2 from './Component2.svelte';

const component: ComponentType = someLogic() ? Component1 : Component2;
const componentOfCertainSubType: ComponentType<SvelteComponent<{ needsThisProp: string }>> = someLogic() ? Component1 : Component2;
</script>

<svelte:component this={component} />
<svelte:component this={componentOfCertainSubType} needsThisProp="hello" />

Type Parameters

Type declaration

  • Optionalelement?: typeof HTMLElement

    The custom element version of the component. Only present if compiled with the customElement compiler option