Although this answer is correct, I want to note that you absolutely don’t have to use this PropsWithChildren helper. (It is primarily useful for the codemod, not manual usage.)
Instead, I find it easier to define them manually.
Before
import * as React from 'react';
type Props = {};
const Component: React.FC<Props> = ({children}) => {...}
After
import * as React from 'react';
type Props = {
children?: React.ReactNode
};
const Component: React.FC<Props> = ({children}) => {...}
That is all that’s needed.
Or you can stop using React.FC altogether.
import * as React from 'react';
type Props = {
children?: React.ReactNode
};
function Component({children}: Props): React.ReactNode {
...
}
In React, children is a regular prop and is not something special. So you need to define it just like you define all the other props. The previous typings that hid it were wrong.