From ea70632de154bda9900ec22d16b29b80bb3ad97d Mon Sep 17 00:00:00 2001 From: Abdul Wahab Date: Thu, 10 Aug 2023 14:14:40 +0200 Subject: [PATCH] Fix instanceOf mistake (#4322) instanceof is a runtime check and interface and types don't exist during runtime. Also TypeScript has a structural type system, which means that they are matched according to the structure of the object and types - not according to instances. For example: interface Person { name: string; age: number } const person = { name: "Ken", age: 25 } if (person instanceof Person) // Error --- .../content/105-type-guards/101-instanceof-operator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/roadmaps/typescript/content/105-type-guards/101-instanceof-operator.md b/src/data/roadmaps/typescript/content/105-type-guards/101-instanceof-operator.md index 52c3f6f8f..e6e1c5f62 100644 --- a/src/data/roadmaps/typescript/content/105-type-guards/101-instanceof-operator.md +++ b/src/data/roadmaps/typescript/content/105-type-guards/101-instanceof-operator.md @@ -1,6 +1,6 @@ # instanceOf operator -The `instanceof` operator is a way to narrow down the type of a variable. It is used to check if an object is an instance of a class, interface, or type. +The `instanceof` operator is a way to narrow down the type of a variable. It is used to check if an object is an instance of a class. ```typescript class Bird {