Skip to content

Docs don't show how to type a dynamic component's bound variableΒ #15988

Open
@anxpara

Description

@anxpara

Describe the bug

The typescript section of the docs shows how to make a dynamic component, but doesn't show how to bind the instance. Migrating from svelte 4 to 5 has been confusing, because my compiler keeps giving me errors and hover hints in terms of the old SvelteComponent.

I posted in the discord server, and we landed on this type:

<script lang="ts">
  import type { Component } from 'svelte';

  interface Props {
    // only components that have at most the "prop"
    // property required can be passed
    DynamicComponent: Component<{ prop: string }>;
  }

  let { DynamicComponent }: Props = $props();

  let dynamicComponent: ReturnType<DynamicComponent>;
</script>

<DynamicComponent bind:this={dynamicComponent} prop="foo" />

Is this the intended way to type a dynamic component 's bound variable? The docs should be updated with an example of whichever type is intended.

Reproduction

The svelte playground completely ignores type annotations :(

Logs

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz
    Memory: 16.97 GB / 31.90 GB
  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE      
    npm: 10.2.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 136.0.7103.114
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    svelte: ^5.0.0 => 5.28.3

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions