-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Svelte 5: Optional children type error #214
Comments
Hi @tomasz13nocon! Thanks for reporting this issue. I've created a PR #215 with a potential fix for this case. Inside this PR you can find the latest addon version tag to download. |
Indeed it works. Thank you! I have some more type errors, especially when working with a bit more complex types for props. It often gives me an "Expression produces a union type that is too complex to represent". I will open separate issue(s) for that, but mentioning it here since it might be related? |
Actually, while optional children work in that canary version, other props being required causes an error now. Minimal example: Button.stories.svelte: <script context="module" lang="ts">
import { defineMeta, setTemplate, type Args } from "@storybook/addon-svelte-csf";
import Button from "./Button.svelte";
const { Story } = defineMeta({
component: Button,
tags: ["autodocs"],
args: {
children: "Click me",
variant: "filled",
},
argTypes: {
variant: { control: "select", options: ["filled", "outlined"] },
children: { control: "text" },
},
});
</script>
<script lang="ts">
setTemplate(template);
</script>
{#snippet template({ children, ...args }: Args<typeof Story>)}
<Button {...args}>{children}</Button>
{/snippet}
<Story name="Primary" args={{ variant: "filled" }} /> Button.svelte: <script lang="ts">
import type { Snippet } from "svelte";
interface Props {
variant: "filled" | "outlined";
children?: Snippet;
}
const { variant, children }: Props = $props();
</script>
<button type="button" class={variant}>
{@render children?.()}
</button> Here's the error: |
Also getting these errors, which seem to be caused by having a non-children Snippet prop which is optional Error occurs here in a story file: {#snippet template({ children, ...args }: Args<typeof Story>)}
<Chip bind:selected {...args}>
{children}
</Chip>
{/snippet} Component props: import { Toggle } from "bits-ui";
interface Props extends Omit<Toggle.RootProps, "pressed" | "onPressedChange"> {
variant?: "assist" | "filter" | "input" | "suggestion";
selected: Toggle.RootProps["pressed"];
onSelectedChange?: Toggle.RootProps["onPressedChange"];
leadingIcon?: Snippet;
trailingIcon?: Snippet;
children: Snippet;
} |
Hey @tomasz13nocon! Firstly, thanks a lot for checking! You're right to be suspicious that they might be related given the circumstances. I admit, I'm not satisfied with the current state of those type helpers |
Describe the bug
Having optional children prop in a component causes children arg within the story to have error:
Type 'string' is not assignable to type 'Snippet<[]>'.
Steps to reproduce the behavior
Take the default example from
next
branch, and in the Button component, make children optional:children?: Snippet;
Environment
The text was updated successfully, but these errors were encountered: