ataractic
ataractic2y ago

Syntax error when getting prop children Element but compiles

Is this error important? How can I fix it? Should I fix it?
8 Replies
marvinh.
marvinh.2y ago
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?
ataractic
ataracticOP2y ago
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
marvinh.
marvinh.2y ago
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 browser
ataractic
ataracticOP2y ago
Thank you! There is so much types named Element that I chose the simplest
marvinh.
marvinh.2y ago
hehe yeah there is definitely a worrying number of these. It's easy to mix them up 😅
ataractic
ataracticOP2y ago
While I'm at it, does ComponentChildren works with multiple children elements?
marvinh.
marvinh.2y ago
yes iirc it's the catchall type we use in Preact
ataractic
ataracticOP2y ago
Thanks 👍

Did you find this page helpful?