Type Checking with instanceof
This lesson delves further into type checking with instanceof and how TypeScript uses it to compare types.
We'll cover the following...
instanceof
with classes
instanceof
also comes from JavaScript and executes at runtime. Nevertheless, TypeScript can handle the test operator that is looking at the prototype chain to figure out the type of object. Like typeof
, if the comparison with instanceof
is positive, the type is narrowed down to the checked type. Instanceof
cannot be used for interface checks and is limited to a class comparison since it relies on the ...