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?
-
1Does this answer your question? How to get a variable type in Typescript?Nisharg Shah– Nisharg Shah2021-08-15 12:17:26 +00:00Commented Aug 15, 2021 at 12:17
Add a comment
|
2 Answers
Did you try the following
class BehaviorSubject {}
let myVariable = new BehaviorSubject()
console.log(myVariable instanceof BehaviorSubject)
4 Comments
Ali Bayat Mokhtari
if you run
console.log(typeof myVariable) it will log ObjectHariom Balhara
I have fixed my suggestion. Please recheck
Joseph Bradshaw
This is specific to rxjs, so creating your own class
BehaviorSubject doesn't help.Hariom Balhara
I added a class example so that the entire code works. I saw that you have got the answer you were looking for :)