• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ``this`` typing is supported only for methods with explicit ``this`` return
2
3Rule ``arkts-this-typing``
4
5**Severity: error**
6
7ArkTS allows type notation using the ``this`` keyword only for a return type
8of an instance method of a class or struct.
9Such methods can only return ``this`` explicitly (``return this``).
10
11## TypeScript
12
13
14```
15    class C {
16        n: number = 0
17
18        m(c: this) {
19            console.log(c)
20        }
21
22        foo(): this {
23            return this.bar();
24        }
25
26        bar(): this {
27            return this;
28        }
29    }
30
31```
32
33## ArkTS
34
35
36```
37    class C {
38        n: number = 0
39
40        m(c: C) {
41            console.log(c)
42        }
43
44        foo(): this {
45            return this;
46        }
47
48        bar(): this {
49            return this;
50        }
51    }
52
53```
54
55
56