A Look at the instanceof Type Guard in TypeScript

1 · · Sept. 12, 2019, 8:21 p.m.
The instanceof operator is used to determine whether or not a type is of a particular constructor function. For example, since an interface can be implemented by several classes, how do we determine which class initializes a particular variable if it’s declared which an interface type? We can achieve that using the instanceof operator. Let’s look at an example: interface Person { id(); } class Chef implements Person { id() { console.log("I am a chef") } cook(){ console.log("I l...