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
Svelte 5: Improve Snippet Typing to allow all types within a snippet body. #11537
Comments
Your code snippet wouldn't work if I pass the string |
So is it not possible to pass snippet body content through a prop? Is there a type of contents within a Snippet body? I want to extend the Button’s children prop (Snippet body) to parent because the prop is going into the Snippet body. how would you type the Parent for anything that goes into Snippet body? string | number | |
If you do I don't really understand the point of this, though. By not using snippets you just limit the capabilities. |
Take a scenario like this:
<script lang="ts">
import Accordion, { type AccordionItems } from "$lib/components/shared/Accordion/Accordion.svelte";
const accordionItems: AccordionItems = [
{
value: 'one',
trigger: "One",
content: 'This is content three'
},
{
value: 'one',
trigger: "Two",
content: 'This is content two'
},
]
</script>
<Accordion items={accordionItems} /> I wanted to avoid typing |
If you want to accept strings and snippets, just accept strings and snippets. To render that, you need to differentiate, otherwise real snippets will not work. {#if typeof content == 'string'}
{content}
{:else}
{@render content()}
{/if} |
Technically I can never accept a snippet due to component API. Can’t pass snippet through props. It’s a loop I will just try to imitate this https://reactnative.dev/docs/react-node as a type that can go in SnippetBody. |
Sure you can pass snippets through props. |
Describe the bug
Component is a Svelte component that has a prop of
children
.children
is of typeSnippet
.There should not be a TypeScript error for anything like strings, numbers, etc that are all allowable within a Snippet's body.
Error:
Type 'string' is not assignable to type '(this: void) => unique symbol & { _: "functions passed to {@render ...} tags must use the
Snippettype imported from \"svelte\""; }'
Reproduction
Note: Reproduction is kinda pointless (as you don't actually see the TS error in REPL, only in VSCode.)
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE5VSy2rDMBD8lWUpJAGT3F3b9HEuBHqsenDtdSNqy0JahxSjfy-ylCdpIDdpmZmdGWnERrZkMf0YUZUdYYrPWmOC_Kv9xW6pZcIEbT-Yyk8yWxmpGdpSfecC2QoshBIsO90bhnVpSDE0pu9gtlyF6zLIzITKVoHuKSqL4Goj29qQygW-trL6gTcSWGSRXAiFCXZ9LRtJNaZsBnLJwe7LwNyrOx1D1SumHefCCw8txRC0m0JIxWSasiII6mvTawujRwjeu03hXUmtif3YXUa73ZL3CuNeAFzsK9b06BUEt8Qw7re59MxLDg_aH-aLy8VfE2paNj4ZUjWZQ8HzxeTzCLnZbKj__r8AEFMGwwmMIe-pf3f4IWG6PI9-fIBgIpBox6Rqe_4o7kpVp6T_m6rldqopC3rFUSCLrgpPibArVX26Pz4IXXs_AwAA
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: