svelte-check-rs-repro-module-type-stripped Svelte Themes

Svelte Check Rs Repro Module Type Stripped

Repro: svelte-check-rs strips type aliases from <script module> when generics= attribute matches

svelte-check-rs bug: module-level type aliases stripped when generics= attribute present

Bug

When a component has both a <script lang="ts" module> block containing type X = unknown declarations and a <script generics="X ..."> instance block whose generic parameter names match those aliases, svelte-check-rs strips the type alias declarations from the generated TypeScript. Any other code referencing the stripped aliases (e.g. default generic parameters) then fails:

src/lib/DataTable.svelte:5:31
Error: Cannot find name 'TValue'. (ts(TS2304))

src/lib/DataTable.svelte:11:47
Error: Cannot find name 'TData'. (ts(TS2304))

src/lib/DataTable.svelte:11:67
Error: Cannot find name 'TValue'. (ts(TS2304))

Native svelte-check preserves the aliases and produces no errors.

Trigger condition

The stripping only happens when:

  1. The alias value is exactly unknown (e.g. type TData = unknown)
  2. A generic parameter in <script generics="..."> has the same name

Aliases with other values (Record<string, unknown>, unions, interfaces) are preserved.

Minimal example

<script lang="ts" module>
  type TData = unknown;
  type TValue = unknown;

  export interface Column<T = TValue> {
    key: string;
    label: string;
    format?: (value: T) => string;
  }

  export interface DataTableProps<TPropData = TData, TPropValue = TValue> {
    columns: Column<TPropValue>[];
    data: TPropData[];
  }
</script>

<script generics="TData extends unknown, TValue extends unknown" lang="ts">
  let { columns, data }: DataTableProps<TData, TValue> = $props();
</script>

Generated TypeScript (--emit-ts)

// === MODULE SCRIPT ===
// type TData = unknown;   ← STRIPPED
// type TValue = unknown;  ← STRIPPED

export interface Column<T = TValue> {          // TValue not found
  key: string;
  label: string;
  format?: (value: T) => string;
}

export interface DataTableProps<TPropData = TData, TPropValue = TValue> {  // TData, TValue not found
  columns: Column<TPropValue>[];
  data: TPropData[];
}

Reproduce

pnpm install
npx svelte-check-rs

Environment

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

Top categories

Loading Svelte Themes