You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Column can be either a string, number, or object. However, svelte sees only the string part. Also, ts-ignore doesn't work (see #1026) which means there's no workaround.
<script lang="ts" context="module">
import type {ComponentType} from 'svelte';
export type ColumnComponent = {
Component: ComponentType;
props?: Record<string, unknown>;
}
export type Column = string | number | ColumnComponent;
</script>
<script lang="ts">
export let columns: string[];
export let items: Record<string, Column>[];
</script>
<table>
<thead>
<tr>
{#each columns as column}
<td>
{column}
</td>
{/each}
</tr>
</thead>
<tbody>
{#each items as item}
<tr>
{#each columns as column}
<td>
{#if typeof item[column] === 'string' || typeof item[column] === 'number'}
{item[column]}
{:else}
<!-- @ts-ignore -->
<svelte:component this={item[column].Component} {...item[column].props} /> <!-- @ts-ignore -->
{/if}
</td>
{/each}
</tr>
{/each}
</tbody>
</table>
Reproduction
See code snippet above. Looks like repl doesn't support typescript.
Duplicate of #1541. This is a limitation of TypeScript's control flow analysis on an array index. The same error happens in a ts file. See ts playground example. In your case, you can workaround with {#const }
Describe the bug
Column
can be either astring
,number
, orobject
. However, svelte sees only the string part. Also, ts-ignore doesn't work (see #1026) which means there's no workaround.Reproduction
See code snippet above. Looks like repl doesn't support typescript.
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: