• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Interface can not extend interfaces with the same method
2
3Rule ``arkts-no-extend-same-prop``
4
5**Severity: error**
6
7In TypeScript, an interface that extends two other interfaces with the same method
8must declare that method with a combined result type. It is not allowed in
9ArkTS because ArkTS does not allow an interface to contain two methods with
10signatures that are  not distinguishable, e.g., two methods that have the same
11parameter lists but different return types.
12
13
14## TypeScript
15
16
17```
18
19    interface Mover {
20        getStatus(): { speed: number }
21    }
22    interface Shaker {
23        getStatus(): { frequency: number }
24    }
25
26    interface MoverShaker extends Mover, Shaker {
27        getStatus(): {
28            speed: number
29            frequency: number
30        }
31    }
32
33    class C implements MoverShaker {
34        private speed: number = 0
35        private frequency: number = 0
36
37        getStatus() {
38            return { speed: this.speed, frequency: this.frequency }
39        }
40    }
41
42```
43
44## ArkTS
45
46
47```
48
49    class MoveStatus {
50        public speed : number
51        constructor() {
52            this.speed = 0
53        }
54    }
55    interface Mover {
56        getMoveStatus(): MoveStatus
57    }
58
59    class ShakeStatus {
60        public frequency : number
61        constructor() {
62            this.frequency = 0
63        }
64    }
65    interface Shaker {
66        getShakeStatus(): ShakeStatus
67    }
68
69    class MoveAndShakeStatus {
70        public speed : number
71        public frequency : number
72        constructor() {
73            this.speed = 0
74            this.frequency = 0
75        }
76    }
77
78    class C implements Mover, Shaker {
79        private move_status : MoveStatus
80        private shake_status : ShakeStatus
81
82        constructor() {
83            this.move_status = new MoveStatus()
84            this.shake_status = new ShakeStatus()
85        }
86
87        public getMoveStatus() : MoveStatus {
88            return this.move_status
89        }
90
91        public getShakeStatus() : ShakeStatus {
92            return this.shake_status
93        }
94
95        public getStatus(): MoveAndShakeStatus {
96            return {
97                speed: this.move_status.speed,
98                frequency: this.shake_status.frequency
99            }
100        }
101    }
102
103```
104
105
106