#Nullish coaleshing object

3 messages · Page 1 of 1 (latest)

past tangle
#

My function gets an object argument ROUTE that can be either Route interface or RouteWithChildren
RouteWithChildren has property children and Route doesn't

ROUTE?.CHILDREN

Why is Typescript complaining Property 'CHILDREN' does not exist on type 'Route'
when i'm using optional chaining? Is there way to avoid this or what is the preferred logic I should use to achieve

ROUTE?.CHILDREN ? (
// code a...
) : (
// code b...
)
pastel radish
past tangle
#

Thank you!