Repository navigation
Replies: 3 comments 4 replies
|
Typescript provides structural typing, so you can not limit children to Box only, any value that satisfies the type of Box will be valid. |
1 reply
|
But how can this be done in Solid? |
1 reply
|
In typescript, you can not. What you are asking is possible in nominal type systems . Typescript provides structural type system. Just look it up on the internet for details. If you want to render only the Box components as children, you can check if child is a Box, then render accordingly. Other than than there is nothing much you can do about it. https://www.solidjs.com/docs/latest#children As a workaround you can attach a Symbol property to the Box and look for it inside Flex's children prop. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
E.g. you have a
<Flex>that may only contain<Box>-ElementsIt would be enough, if this only works on typescript type-level, no runtime check necessary.
Simply change the type of props.children leads to an TS-Error:
Type 'Element' is not assignable to type 'ParentComponent<BoxProps> & Element'. Type 'undefined' is not assignable to type 'ParentComponent<BoxProps> & Element'.ts(2322)All reactions