In the following code I want to print out the "dayNumber" property, in case the item is an object otherwise It should print out the number 0. I can't get rid of the error and I don't understand why.
I'm trying to use the nullish coalescing operator, which seams appropriate in this case.

Because typescript is a safety type and uses Type Guards to prevent you from calling a parameter don't declare it, so you can't call
dayNumberwhen the type is Literal0the nullish coalescing and Optional Chaining use it when the parameter/property is declare as optional in TypeScript and The onion of type0andDaydoesn't have this property (but in JS you can do it because don't have types to compile check it and complain), so for solve the problem you must use type guards technics (in, instanceof, ..etc) it makes more code, or declare the array asany[]and escape from type checking