-
-
Notifications
You must be signed in to change notification settings - Fork 170
Description
Describe the bug
When using JSX JavaScript expressions within a Text component, TypeScript will throw a type error:
<Text>There are {3} bananas in the bunch</Text>
^~~~
This JSX tag's 'children' prop expects a single child of type 'string | number | undefined', but multiple children were provided. ts(2746)
No overload matches this call.
This JSX tag's 'children' prop expects a single child of type 'string | number | undefined', but multiple children were provided.
Overload 2 of 2, '(props: PropsWithChildren<TextProps>, context?: any): any', gave the following error.
Type '{ children: ReactText[]; }' is not assignable to type 'TextProps'.
Types of property 'children' are incompatible.
Type 'ReactText[]' is not assignable to type 'string | number | undefined'.
Type 'ReactText[]' is not assignable to type 'string'. ts(2769)To Reproduce
Steps to reproduce the behavior:
- Create a component
- Render a text component that contains a string with JavaScript expressions:
<Text>There are {3} bananas in the bunch</Text>
- See type error.
Expected behavior
The Text component should accept JavaScript expressions, allowing children to be of string, number and an array of those.
The type of TextProps["children"] should be changed to React.ReactText | React.ReactText[] to allow JavaScript expressions.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: macOS Mojave
- NodeGUI version: 0.15.2
- React NodeGUI version: 0.5.0
- OS Version: 10.14.5
Additional context
While you can put use string template literals, this won't be identical to how JSX handles text nodes with expressions. The children of a component using expressions should be an array of text nodes (Array<string | number>), ideally using React.ReactText.
