de1ad893-69ec-4578-8599-83c3073351b9.js
2.21 KB
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
59
60
61
62
63
64
65
"use strict";
cc._RF.push(module, 'de1adiTaexFeIWZg8MHM1G5', 'TypeTest');
// script/common/type/TypeTest.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Type_1 = require("./Type");
let AbilityAType = Type_1.Type.declare("AbilityA");
let AbilityBType = Type_1.Type.declare("AbilityB");
let AbilityCType = Type_1.Type.declare("AbilityC", AbilityAType);
///////////////////////
class ListItem {
}
class ListItemA extends ListItem {
constructor() {
super(...arguments);
this.__assignableTypes = ListItemAType.assignableTypes;
this.a = "";
this.b = "";
}
}
// 类型对象的规则: T=类型, self_id=T的id, superTypes: extends 或 implments的 (NominalTypeSupported) T
let ListItemAType = Type_1.Type.declare("ListItemA", AbilityAType, AbilityBType);
class ListItemB extends ListItem {
constructor() {
super(...arguments);
this.__assignableTypes = ListItemBType.assignableTypes;
this.a = "";
}
}
let ListItemBType = Type_1.Type.declare("ListItemB", AbilityCType);
class ListItemC extends ListItemA {
constructor() {
super(...arguments);
this.__assignableTypes = ListItemCType.assignableTypes;
}
}
let ListItemCType = Type_1.Type.declare("ListItemC", ListItemAType);
class ListItemD extends ListItemC {
constructor() {
super(...arguments);
this.__assignableTypes = ListItemDType.assignableTypes;
}
}
let ListItemDType = Type_1.Type.declare("ListItemD", ListItemCType, AbilityCType);
let item = new ListItemA;
console.log("typeId =" + item.__assignableTypes);
console.log(AbilityAType.isInstanceOf(item)); // expect true
console.log(AbilityBType.isInstanceOf(item)); // expect true
console.log(AbilityCType.isInstanceOf(item)); // expect false
let item2 = new ListItemB;
console.log(AbilityCType.isInstanceOf(item2)); // expect true
console.log(AbilityAType.isInstanceOf(item2)); // expect true
console.log(AbilityBType.isInstanceOf(item2)); // expect false
// throw Error
try {
Type_1.Type.declare("ListItemD", ListItemCType, AbilityCType);
}
catch (e) {
console.log(e.message);
}
//another isInstanceOf
console.log(Type_1.Type.isInstanceOf("AbilityB", item2)); // expect false
cc._RF.pop();