-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathas_class.ts
More file actions
58 lines (42 loc) · 955 Bytes
/
as_class.ts
File metadata and controls
58 lines (42 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export default {}
class Comp {
constructor() {
}
a(){
console.log('~~~~~~~~~~~~~a')
}
}
class Page extends Comp {
constructor() {
super()
}
b() {
console.log('~~~~~~~~~~~~~b')
}
hook() {}
}
class Home extends Page {
constructor (){
super()
}
c() {
console.log('~~~~~~~~~~~~~c')
}
hook() {
console.log('~~~~~~~~~~hook')
}
}
let home: Home = new Home()
home.c()
// 子类 as成父类或以上
// [ERROR] console - Static type doesn't support type assertion
// 使用场景 框架中对页面实例进行类型提升放入框架数据集合
let p: Page = home as Page
let cp: Comp = home as Comp
// 父类或以上 as成子类
// 使用场景 框架中调用具体页面方法时获取页面实例类型 调用具体方法
// [ERROR] console - Static type doesn't support type assertion
let child: Page = cp as Page
let child1: Home = p as Home
let child2: Home = cp as Home
child2.c()