Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'children' does not exist on type '{}'

I'm having a typescript error. It says that 'children' does not exist on type '{}' even though this syntax works on my other projects.

like image 857
Jerome Bravo Avatar asked Feb 15 '26 11:02

Jerome Bravo


1 Answers

I'm guessing this new app is on React 18.

React 18 removed children from the FC type. If you want it back you need to add it to the props yourself.

const Foo: React.FC<{ children: React.ReactNode }> = ({ children }) => <>{children}</>

Or preferably, don't use the FC type at all:

interface Props {
    children: React.ReactNode
}

function Foo({ children }: Props) {
    return<>{children}</>
}
like image 59
Alex Wayne Avatar answered Feb 18 '26 00:02

Alex Wayne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!