• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  ``instanceof`` operator is partially supported
2
3Rule ``arkts-instanceof-ref-types``
4
5**Severity: error**
6
7In TypeScript, the left-hand side of an ``instanceof`` expression must be of the type
8``any``, an object type or a type parameter; the result is ``false`` otherwise.
9In ArkTS, the left-hand side expression may be of any reference type;
10a compile-time error occurs otherwise. In addition, the left operand in ArkTS
11cannot be a type.
12
13
14## TypeScript
15
16
17```
18
19    class X {
20        // ...
21    }
22
23    let a = (new X()) instanceof Object // true
24    let b = (new X()) instanceof X      // true
25
26    let c = X instanceof Object // true, left operand is a type
27    let d = X instanceof X      // false, left operand is a type
28
29```
30
31## ArkTS
32
33
34```
35
36    class X {
37        // ...
38    }
39
40    let a = (new X()) instanceof Object // true
41    let b = (new X()) instanceof X      // true
42
43    let c = X instanceof Object // Compile-time error, left operand is a type
44    let d = X instanceof X      // Compile-time error, left operand is a type
45
46```
47
48
49