I have a function that can return 1 out of 3 possible types:
getFoo(): Observable<Foo> | Promise<Foo> | Foo {
//return 1 of 3 types
}
So how can I ensure the exact type after calling:
const foo = someClassObj.getFoo();
If I now want to get the data from foo, how can I know if it's Observable, Promise, or class instance Foo? When I try instanceof or typeof, they only detect 'object'.
.thenand.subscribe, see e.g. stackoverflow.com/q/27746304/3001761. But it might be easier to rewrite that to be more consistent.isObservable()that you can use. For checking if it is a promise, refer to this answer stackoverflow.com/a/27746373/6513723