-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Open
Description
Describe the bug
mount() doesn't enforce generic component prop constraints. The Component<Props> type erases the component-level generic T, so Props resolves to the default/widened type and TypeScript can't enforce the extends constraint on props passed to mount().
Expected: type error when props violate the component's generic constraint.
Actual: invalid props silently accepted.
Note: using the component in a template does correctly catch the error.
Reproduction
GenericList.svelte
<script lang="ts" generics="T extends { id: number; label: string }">
let { items = [] }: { items: T[] } = $props()
</script>
{#each items as item}
<div>{item.label} (#{item.id})</div>
{/each}App.svelte
<script lang="ts">
import { mount } from 'svelte'
import GenericList from './GenericList.svelte'
// should error: { foo: 42 } doesn't satisfy { id: number; label: string }
// but mount() accepts it without complaint
mount(GenericList, {
target: document.body,
props: { items: [{ foo: 42 }] },
})
</script>Severity
annoyance
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels