[Tooltip] TypeScript issue with children type and React.FunctionComponent
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
When creating functional wrapper components in Typescript, I get type errors due to Material-UI expecting a ReactElement<any, any>
“children” prop while React provides a ReactNode
(due to React.FunctionComponent<Props>
wrapping my props into React.PropsWithChildren
).
When compiling in strict TS mode, this breaks the build.
In non-strict mode, the error is ignored and the component works well.
Expected Behavior 🤔
Successful compilation.
Steps to Reproduce 🕹
Please check out https://codesandbox.io/s/sad-dubinsky-pdktq?file=/src/Tooltip.tsx
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.11.0 |
React | v17.0.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Typescript error on React 18 (Property 'children' does not exist ...
Typescript complains once you update to React 18, ... Type error: Type 'TooltipProps' recursively references itself as a base type.
Read more >TypeScript error: Property 'children' does not exist on type ...
I tried out several types but only any works which is not what I want. Usually I used ReactNode for children props and...
Read more >visx/tooltip documentation
Portal is a component which simply renders its children inside a div element appended to document.body created by ReactDOM . A Portal can...
Read more >Component Configuration Syntax: DevExtreme - JavaScript UI ...
Properties of the Object Type. Use nested configuration components. In the following example, we configure the Chart UI component's tooltip property: Function ......
Read more >typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I generally don’t recommend
React.FunctionComponent
because it injects achildren
type. See https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components/ for more information.You’re looking for something like
function Component(props: { children?: React.Element<any, any>})
. Hope that helps.They do. You just have to make sure
children
has the same type thatTooltip
’schildren
have.