svelte-check-rs-repro-each-block-comma Svelte Themes

Svelte Check Rs Repro Each Block Comma

Repro: svelte-check-rs generates invalid TS for {#each {length}, index} syntax

svelte-check-rs bug: {#each { length }, index} generates invalid TypeScript

Bug

The Svelte-documented {#each { length: N }, index} comma syntax for rendering N items generates invalid TypeScript. The transformer treats the comma as a JavaScript variable declaration list instead of Svelte's index parameter.

Errors produced:

src/lib/Skeleton.svelte:5:27
Error: 'const' declarations must be initialized. (ts(TS1155))

src/lib/Skeleton.svelte:5:27
Error: Variable 'i' implicitly has an 'any' type. (ts(TS7005))

src/routes/+page.svelte:7:23
Error: 'const' declarations must be initialized. (ts(TS1155))

Native svelte-check handles this syntax correctly.

Minimal example

{#each { length: 4 }, i}
  <div>placeholder {i}</div>
{/each}

Generated TypeScript (--emit-ts)

// What svelte-check-rs generates (broken):
const __each_1 = { length: 4 }, i;   // comma parsed as variable declaration list
for (const  of __each_1) {           // empty iterator variable
  i;
}

// What it should generate:
for (const [i, _] of __svelte_each_indexed({ length: 4 })) {
  // ...
}

Reproduce

pnpm install
npx svelte-check-rs

Environment

  • svelte-check-rs 0.9.16
  • Svelte 5 / SvelteKit 2

Top categories

Loading Svelte Themes