-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSX Children Tuple with single element #30918
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
Comments
I don't understand what you expect to happen here. Your function says that this code is legal: const Component = (props: { children: [ JSX.Element ] }) => props.children.slice(0);
const test = <Component><element /></Component>; // Should not throw an error But that code is going to throw an error at runtime. Why should something that manifestly defies the specified types pass the type checking? |
FYI: Impossible in |
@RyanCavanaugh @weswigham Exactly! Don't you agree that there should be the option, to opt-out of these react-specific things? |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Search Terms:
When A single element is given as a Child, it is not handled as an Array.
Code
Expected behavior:
There should not be a completely different behaviour from TypeScript when a single Child is present in a Tuple.
Actual behavior:
The following error is thrown: This JSX tag's 'children' prop expects type '[Element]' which requires multiple children, but only a single child was provided
I am aware that React behaves that way, but the JSX-Language states that everything between JSXOpeningElement and JSXSelfClosingElement are JSXChildren. https://github.com/facebook/jsx
The text was updated successfully, but these errors were encountered: