Below is the code snippet used in a component:
- Component.svelte:
<script lang="ts">
type T = $$Generic;
export let loading = false;
export let error = false;
export let value: T | null | undefined = undefined;
</script>
<div>
{#if loading}
Loading...
{:else if error}
Error...
{:else if value}
<slot {value} />
{/if}
</div>
Usage example:
<Component
loading={$service.loading}
error={$service.error}
value={$service.data?.item}
let:value={item}
>
<!-- At this point 'item' may still be `null` or `undefined`, why? -->
{item.description}
</Component>
The expectation is for the item
variable to be not null and not undefined due to the {:else if value}
condition in Component.svelte
.
Is this assumption incorrect?