PHANTOM
🇮🇳 IN
Skip to content

[types]: Omit children from svelte types in react bindings#3

Merged
benjaminknox merged 1 commit intobpk/svelte5from
fix-svelte-react-children-prop-type
May 13, 2025
Merged

[types]: Omit children from svelte types in react bindings#3
benjaminknox merged 1 commit intobpk/svelte5from
fix-svelte-react-children-prop-type

Conversation

@benjaminknox
Copy link
Owner

@benjaminknox benjaminknox commented May 12, 2025

What?

In the svelte 5 react bindings, the children prop type on components resolve to Snippet<[]> and we get type errors on something like this:

 <LeoButton href="#foo">Link button!</LeoButton>
// or
<leo-menu-item onClick={handleAction}>Llama2-13b</leo-menu-item>

The errors looked something like this:

TS2747: 'leo-option' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of 'children' is '(Snippet<[]> & (string | Element[])) | undefined'.

Solution: Omit the children prop on the imported svelte types in a few areas, this seems to let it use the correct react children prop for types.

Details

  • Omit children in scripts/gen-react-bindings.js in the imported svelte component types
  • For leo-menu-item and leo-option:
    • From HTMLAttributes type from svelte/elements omit the children prop
    • Define children with the type string | Elements[]
  • Abstracts the new HTMLAttributes to the components/svelte-react.ts file

@benjaminknox benjaminknox mentioned this pull request May 12, 2025
5 tasks
@benjaminknox benjaminknox force-pushed the fix-svelte-react-children-prop-type branch from f38fdd9 to 23c7cc0 Compare May 13, 2025 22:44
@benjaminknox
Copy link
Owner Author

Going to merge into the Svelte5 branch that has a PR open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants