svelte-check-rs-repro-classname Svelte Themes

Svelte Check Rs Repro Classname

Minimal repro: svelte-check-rs TS2749 from class:className destructuring without explicit Props type

svelte-check-rs TS2749 reproduction: class: className destructuring

Minimal 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.

The bug

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))

Root cause

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.

Expected behavior

No error. The class: className destructuring pattern is idiomatic Svelte 5 and should work without an explicit Props type.

Workaround

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>

Reproduce

pnpm install

# Shows TS2749 error (bug)
pnpm check:rs

# Shows 0 errors (correct)
pnpm check:legacy

Versions

  • svelte-check-rs: 0.9.18
  • svelte-check: 4.4.8
  • svelte: 5.55.9
  • typescript: 6.0.3
  • tsgo (bundled by svelte-check-rs): 7.0.0-dev

Top categories

Loading Svelte Themes