This is completely normal - you have come into territory where TypeScript is trying to protect you from accessing potentially non-existing property.
If you take a look at documentation for union types you will find this:
If we have a value that has a union type, we can only access members that are common to all types in the union.
You need to refactor your solution to handle this case in a better way. Btw, why you don't use intersection types?
You should look at type guards : typescriptlang.org/docs/handbook/a...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is completely normal - you have come into territory where TypeScript is trying to protect you from accessing potentially non-existing property.
If you take a look at documentation for union types you will find this:
You need to refactor your solution to handle this case in a better way. Btw, why you don't use intersection types?
You should look at type guards : typescriptlang.org/docs/handbook/a...