class: className destructuringMinimal reproduction for a bug in [email protected] where destructuring class as className from $props() without an explicit Props type annotation causes a spurious TS2749 error. Regular svelte-check does not report this error.
When a Svelte 5 component destructures the class prop with an alias:
<script lang="ts">
let { children, class: className = "" } = $props();
</script>
<span class={className}>
{@render children?.()}
</span>
svelte-check-rs reports:
Error: 'className' refers to a value, but is being used as a type here.
Did you mean 'typeof className'? (ts(TS2749))
svelte-check-rs generates TypeScript with the destructured variable name className in a type position:
return { props: null as any as { children: unknown; class?: className }, ... };
// ^^^^^^^^^
// should be `string`, not the variable `className`
Regular svelte-check (which uses svelte2tsx) correctly infers the type rather than using the alias name.
No error. The class: className destructuring pattern is idiomatic Svelte 5 and should work without an explicit Props type.
Adding an explicit Props interface avoids the error:
<script lang="ts">
import type { Snippet } from "svelte";
interface Props { children?: Snippet; class?: string; }
let { children, class: className = "" }: Props = $props();
</script>
pnpm install
# Shows TS2749 error (bug)
pnpm check:rs
# Shows 0 errors (correct)
pnpm check:legacy
svelte-check-rs: 0.9.18svelte-check: 4.4.8svelte: 5.55.9typescript: 6.0.3tsgo (bundled by svelte-check-rs): 7.0.0-dev