I'm trying to wrap my head around how to access an element that exists on an object of a specific type but is defined as a type predicate.
For example, let's say we have a Team
defined as:
let team$: Observable<ErrorModel | Team>
The result of a successful call to this observable is of type Team
, which has a code
, while the ErrorModel
does not. This leads Typescript linter to throw an error saying
code does not exist on type ErrorModel | Team
.
So essentially,
return team$.subscribe(response => {
console.log(response.code);
}
How can I access response.code
in this scenario? Even using typeof
won't resolve the lint error.