-
Notifications
You must be signed in to change notification settings - Fork 0
/
WatchComputed.test.ts
90 lines (80 loc) · 2.4 KB
/
WatchComputed.test.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Checking, type Test } from "hry-types";
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
import type { RootComponentType } from "../../../RootComponent/RootComponentType";
import { SubComponent } from "../..";
type RootDoc = RootComponentType<{
properties: {
obj: Mock_User | null;
};
data: {
num: number;
};
store: {
bool: boolean;
};
}>;
type CompDoc = ComponentType<{
properties: {
aaa_obj: Mock_User | null;
aaa_str: string;
aaa_num: number;
aaa_bool: boolean;
};
}>;
/**
* watch computed字段时需要手写类型,可悬停鼠标到key查看类型
*/
SubComponent<RootDoc, CompDoc>()({
computed: {
aaa_str(): string {
return this.data.aaa_num.toString();
},
aaa_num(): number {
return 123;
},
aaa_bool(): boolean {
return this.data.bool;
},
aaa_obj(): Mock_User {
return {} as Mock_User;
},
},
watch: {
aaa_num(newValue: number, oldValue: number) {
void oldValue;
Checking<number, typeof newValue, Test.Pass>();
Checking<number, typeof oldValue, Test.Pass>();
},
aaa_str(newValue: string, oldValue: string) {
void oldValue;
Checking<string, typeof newValue, Test.Pass>();
Checking<string, typeof oldValue, Test.Pass>();
},
aaa_bool(newValue: boolean, oldValue: boolean) {
void oldValue;
Checking<boolean, typeof newValue, Test.Pass>();
Checking<boolean, typeof oldValue, Test.Pass>();
},
aaa_obj(newValue: Mock_User, oldValue: Mock_User | null) {
void oldValue;
Checking<Mock_User, typeof newValue, Test.Pass>();
Checking<Mock_User | null, typeof oldValue, Test.Pass>();
},
"aaa_obj.**"(newValue: Mock_User, oldValue: Mock_User | null) {
void oldValue;
Checking<Mock_User, typeof newValue, Test.Pass>();
Checking<Mock_User | null, typeof oldValue, Test.Pass>();
},
"aaa_obj.id"(newValue: string, oldValue: string) {
void oldValue;
Checking<string, typeof newValue, Test.Pass>();
Checking<string, typeof oldValue, Test.Pass>();
},
"aaa_obj.age"(newValue: number, oldValue: number) {
void oldValue;
Checking<number, typeof newValue, Test.Pass>();
Checking<number, typeof oldValue, Test.Pass>();
},
},
});