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

[Feature]: Typescript - Add typings to both <Template> and <Story> args #68

Closed
AcePetrucci opened this issue Sep 2, 2022 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@AcePetrucci
Copy link

Describe the bug

Whenever I use both the <Template> and <Story> components, it would be great to be able to set the expected type of let:args.

Ex:

<script lang="ts">
  import Choice from './Choice.svelte';
  import choiceProps from './choiceProps.ts';
</script>

<Template let:args id="ChoiceTemplate">
  // Ideally I would have the option to set that args has the choiceProps type
  <Choice {...args} />
</Template>

<Story
  id="ChoiceStory"
  name="Choice"
  template="ChoiceTemplate"
  args={{
    choiceText: 'Choice 1',
    value: 'choice-1',
    name: 'choice-1'
  }} // Same thing here
/>
@AcePetrucci AcePetrucci added the bug Something isn't working label Sep 2, 2022
@j3rem1e j3rem1e added enhancement New feature or request and removed bug Something isn't working labels Oct 1, 2022
@Masstronaut
Copy link

Masstronaut commented Aug 16, 2023

I'm not sure this is solveable within svelte-csf; svelte doesn't have support for typescript outside of the script tags, which has been an open issue for several years. See the issue at @sveltejs/svelte #4701

As a workaround, would this work?

<script lang="ts">
  import Choice from './Choice.svelte';
  import choiceProps from './choiceProps.ts';
  const choiceArgs = {
    choiceText: 'Choice 1',
    value: 'choice-1',
    name: 'choice-1'
  } satisfies choiceProps;
</script>

<Template let:args id="ChoiceTemplate">
  // Ideally I would have the option to set that args has the choiceProps type
  <Choice {...args} />
</Template>

<Story
  id="ChoiceStory"
  name="Choice"
  template="ChoiceTemplate"
  args={choiceArgs}
/>

@benmccann
Copy link
Contributor

I'm not sure what this is really requesting to change in addon-svelte-csf as it seems like something that would need to be addressed in Svelte itself as @Masstronaut suggested. His suggestion seems like a reasonable one in the meantime. Given that, I'm going to close this in favor of sveltejs/svelte#4701

@Masstronaut
Copy link

@benmccann in case it's not on your roadmap, svelte 5 adds typescript support in the svelte markup sveltejs/svelte#9482, so I believe this should be possible now (and greatly appreciated! 🙏)

Not sure if it makes more sense to re-open here or spin up a new issue for it. It would require svelte 5, making it a potentially breaking change for svelte 4 users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants