I have a complex type ReactNode from @types/react 16.9.17 version and TypeScript v3.7.4 version.
import React, { ReactNode } from 'react';
and I want to reduce this type to type, which has property children.
I'm trying to achieve this using implicit type-guards:
import React, { ReactNode } from 'react';
function func(x: ReactNode) {
if (typeof x === 'object'&& x !== null && x.hasOwnProperty("children")) {
x.children
}
}
but I see error Property 'children' does not exist on type '{}'.
Questions:
Why I see this error (why typescript doesn't eliminate empty
{}
type afterhasOwnProperty()
check)?How in general eliminate
{}
type from{} | Type
types?- How to reduce ReactNode type to type, having children property?