Within a component, I have a public member that is defined as follows:
public docId$: Observable<number | string>;
This means that the document ID can either be an integer or a string. Upon initializing in ngOnInit
, I have the following code snippet:
this.docId$.subscribe(value => {
// perform operations using the value
// when the value is a string, it evaluates to NaN
});
Unfortunately, this setup doesn't handle cases where the document ID is a string properly. The value ends up being NaN
. Is there a way to make observables of union types work correctly in this scenario?