-
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
fix: Resolve existing type issues #219
Conversation
This is outcome of discussion at: #216
…ook/svelte` on legacy
@paoloricciuti Should we create an issue on sveltejs/language-tools regarding this one? |
I'll investigate a bit better but from what I've seen the transformation is actually correct...the type is lost when TS emit the DTS. |
examples/Button.stories.svelte
Outdated
@@ -19,7 +20,7 @@ | |||
component: Button, | |||
tags: ['autodocs'], | |||
args: { | |||
children: 'Click me', | |||
children: createRawSnippet(() => ({ render: () => 'Click me' })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good example we want to document, and I don't think it's needed because of line 42 below?
If it's to satisfy types, then I think we should use type modifications instead like as
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing to:
- children: createRawSnippet(() => ({ render: () => 'Click me' })),
+ children: 'Click me' as Snippet,
will produce the error:
Conversion of type 'string' to type 'Snippet<[]>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. [2352]
So, the workaround is:
- children: 'Click me' as Snippet,
+ children: 'Click me' as unknown as Snippet,
Which is cumbersome. Shall we proceed with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I provided another alternative, which can be reverted: 104d5e0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait but do you want a snippet or a string? Because those are not interchangeable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we want a string here, because we convert it to a snippet down in the template below:
This procedure ensures you can easily modify the arg as a string in the Control panel, while it still being passed as a snippet to the component.
But it's slightly cumbersome, and I haven't found a way yet to support this pretty common use case better yet - ideas welcome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xeho91 your alternative looks cleaner, but now it doesn't allow you to modify it in Controls anymore though. but let's stick with it. 👍
children: createRawSnippet(() => ({ | ||
render: () => 'Click me', | ||
})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment, this shouldn't be necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have comments, but I'm approving, and letting you decide if you want to act on them or not. 🙂
🚀 PR was released in |
Things to note
TOverrideArgs
which was incomplete.I believe is better to focus on getting types to work correctly than adding a new incomplete feature - and we haven't got close on achieving it.
Cmp
instead ofCmpOrArgs
as the base generic type parameter to simplify the type system in this addon project#
imports (which uses map frompkg.imports
) inside./src/runtime/**/*
-svelte2tsx
doesn't support it (yet?) - ❤️ @paoloricciuti for detailed investigation📦 Published PR as canary version:
4.1.8--canary.219.161a0fb.0
✨ Test out this PR locally via:
Version
Published prerelease version:
v5.0.0-next.11
Changelog
💥 Breaking Change
@storybook/docs-tools
dependency #190 (@JReinhold)🚀 Enhancement
🐛 Bug Fix
parameters
attribute from legacy<Story>
being removed #224 (@xeho91)enhanceRollupError
in Vite #222 (@JReinhold)context="module"
withmodule
#217 (@xeho91)autodocs
tag issue and extractingrawCode
#201 (@xeho91)next
Example.stories.svelte
(@xeho91)🏠 Internal
Authors: 4