Skip to content
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] Typescript support - types in Args<typeof Story> are optional when types of the Component aren't #232

Closed
fivaz3 opened this issue Nov 16, 2024 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@fivaz3
Copy link

fivaz3 commented Nov 16, 2024

Describe the bug

Typescript support - types in Args are optional when types of the Component aren't

Steps to reproduce the behavior

create a clean Sveltekit project with TS

npx sv create my-app

add storybook to the project

npx storybook@latest init

then go to the story file src/stories/Button.stories.svelte that comes with the storybook installation

and add a template with the typing like it's shown in this lib's readme:

<script module lang="ts">
    import {type Args, defineMeta,setTemplate} from '@storybook/addon-svelte-csf';
</script>
<script>
    setTemplate(template);
</script>

{#snippet template(args: Args<typeof Story>)}
    <div>
        <Button {...args}/>
    </div>
{/snippet}

then run the check command from package.json

Svelte: Type
{
primary?: boolean;
backgroundColor?: string;
size?: "small" | "medium" | "large";
label?: string | undefined;
onClick?: () => void;
}

is not assignable to type Props
Types of property label are incompatible.
Type string | undefined is not assignable to type string
Type undefined is not assignable to type string

Expected behavior

this error shouldn't exist, or at least it should be addressed in the docs how to avoid it

Screenshots and/or logs

Image

@fivaz3 fivaz3 added the bug Something isn't working label Nov 16, 2024
@fivaz3 fivaz3 changed the title [Bug] [Bug] Typescript support - types in Args<typeof Story> are optional when types of the Component aren't Nov 16, 2024
@xeho91
Copy link
Collaborator

xeho91 commented Nov 16, 2024

Hi, sorry you're encountering this issue. Is known one and a duplicate of #216. There's a temporary workaround inside.

We're in the process of rethinking the setTemplate API (discussion on the channel for Svelte in Storybook Discord), and along with it those type helpers - Args & StoryContext.

@xeho91 xeho91 added the duplicate This issue or pull request already exists label Nov 16, 2024
@fivaz3
Copy link
Author

fivaz3 commented Nov 17, 2024

No problem, I will follow the progress on the other issue and close this one. Despite the issue, congratulations on this amazing library!

@fivaz3 fivaz3 closed this as completed Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants