-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
JSX usage example not working #1419
Comments
Hi @msonnemans! Thank you for bringing up this issue. I've created a new PR, #1420. With it, you'll be able to use |
Thanks @yusukebe #1420 looks good! However one immediate note in this case: const Example: FC<{value: boolean}> = ({ value, children }) => {
if (value) return children;
return <div>{children}</div>;
}; It is a common scenario where you want to define a component that either does something with a component or, for some reason, just passes the original children along. At the moment |
Thanks for checking it.
Yeah, I understand what you mean. But, it's difficult to make the types correct, so in this case, you can write like the following: if (value) return <>{children}</> This like a "work around", but I think not so bad. |
This is fixed! |
What version of Hono are you using?
3.5.8
What runtime/platform is your app running on?
local
What steps can reproduce the bug?
Result: the typescript compiler indicates that there is a type error for the
<Layout>
component because Layout only accepts children as astring
and not astring[]
.What is the expected behavior?
For the documented example to have correct typing.
What do you see instead?
The opposite.
Additional information
I think the solution isn't to type Layout with
string[]
. Instead, I think the fundamental problem should be solved: JSX Elements should be able to take either one or multiple child nodes, as if they had<Fragment>
baked in. That way I could create a functional component that can either return a node or returns its children directly. There shouldn't be any distinction.Consider:
In this example, Test2 will throw a type error. However, if changing the component children type to
HtmlEscapedString[]
, then both Tests will throw an error.The text was updated successfully, but these errors were encountered: