type myType = { subtitle: string, title: string } | {};
const someVar: myType = { title: 'some-title', subtitle: 'some subtitle'}
const myTitle: string = someVar?.title;
I get this type error when I try to access title
value from someVar
object. Now, what I don't understand is why wouldI get this type error. I checked the documentation but I don't understand its implication. Union means I can specify possible types but here behaviour seems to be different. Any idea why's that
Property 'title' does not exist on type '{} | { subtitle: string; title: string; }'.
Property 'title' does not exist on type '{}'.ts(2339)