Syntax error when getting prop children Element but compiles
Is this error important? How can I fix it? Should I fix it?
8 Replies
That error is a type-only error and won't affect how your project runs. Nonetheless I'm curious how it came to be. Do you have a reproduction case we could take a look at?
I just created the Section component and put Element type for the children
Then I pass the div containing the chart.
Finally vscode gives me this error
ohh right, I just noticed. The
Element
type refers to a DOM node in the browser. But here in JSX we are not dealing with actual DOM nodes. The whole idea behind JSX is that you only deal with JSX objects. That's why TS is complaining here. What you want to use as a type instead is ComponentChildren
from preact
you can think of the JSX as being only a description based on which the final HTML Elements will be created in the browserThank you!
There is so much types named Element that I chose the simplest
hehe yeah there is definitely a worrying number of these. It's easy to mix them up 😅
While I'm at it, does ComponentChildren works with multiple children elements?
yes
iirc it's the catchall type we use in Preact
Thanks 👍