0

I have a variable which can have type of Date or BehaviorSubject<Date | null>. I wanna know how can i check if the variable is a BehaviorSubject or not?

1

2 Answers 2

3

If you do this in JavaScript you can do:

const behaviorSubject = new Rx.BehaviorSubject();
const isBehaviorSubject = behaviorSubject instanceof Rx.BehaviorSubject;
Sign up to request clarification or add additional context in comments.

Comments

1

Did you try the following

class BehaviorSubject {}
let myVariable = new BehaviorSubject()
console.log(myVariable instanceof BehaviorSubject)

4 Comments

if you run console.log(typeof myVariable) it will log Object
I have fixed my suggestion. Please recheck
This is specific to rxjs, so creating your own class BehaviorSubject doesn't help.
I added a class example so that the entire code works. I saw that you have got the answer you were looking for :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.