question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Nov 20, 2020

I generally don’t recommend React.FunctionComponent because it injects a children 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.

1reaction
eps1loncommented, Nov 20, 2020

They do. You just have to make sure children has the same type that Tooltip’s children have.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found