• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  ``new.target`` is not supported
2
3Rule ``arkts-no-new-target``
4
5**Severity: error**
6
7ArkTS does not support ``new.target`` because there is no concept of runtime
8prototype inheritance in the language. This feature is considered not applicable
9to static typing.
10
11
12## TypeScript
13
14
15```
16
17    class CustomError extends Error {
18        constructor(message?: string) {
19            // 'Error' breaks prototype chain here:
20            super(message)
21
22            // Restore prototype chain:
23            Object.setPrototypeOf(this, new.target.prototype)
24        }
25    }
26
27```
28
29## ArkTS
30
31
32```
33
34    class CustomError extends Error {
35        constructor(message?: string) {
36            // Call parent's constructor, inheritance chain is static and
37            // cannot be modified in runtime
38            super(message)
39            console.log(this instanceof Error) // true
40        }
41    }
42    let ce = new CustomError()
43
44```
45
46## See also
47
48- Recipe 136:  Prototype assignment is not supported (``arkts-no-prototype-assignment``)
49
50
51