annil 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +2 -2
- package/dist/api/DefineComponent/collectOptionsForComponent.js +55 -6
- package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
- package/dist/api/DefineComponent/index.d.ts +2 -2
- package/dist/api/RootComponent/Computed/ComputedOption.d.ts +2 -2
- package/dist/api/RootComponent/Computed/GetComputedDoc.d.ts +2 -2
- package/dist/api/RootComponent/Computed/test/normal.test.js +5 -12
- package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +2 -2
- package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -1
- package/dist/api/RootComponent/Data/DataOption.d.ts +2 -2
- package/dist/api/RootComponent/Data/GetDataDoc.d.ts +1 -4
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.d.ts +3 -2
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.js +5 -5
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.js.map +1 -1
- package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +6 -5
- package/dist/api/RootComponent/Events/EventsOption.d.ts +2 -3
- package/dist/api/RootComponent/Events/test/normal.test.js +1 -1
- package/dist/api/RootComponent/Events/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +5 -4
- package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +6 -7
- package/dist/api/RootComponent/PageLifetimes/test/error.test.js +3 -1
- package/dist/api/RootComponent/PageLifetimes/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/PageLifetimes/test/normal.test.js +3 -1
- package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/RootComponentDoc.d.ts +17 -3
- package/dist/api/RootComponent/Store/GeTStoreDoc.d.ts +1 -1
- package/dist/api/RootComponent/Store/StoreOption.d.ts +2 -2
- package/dist/api/RootComponent/Store/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +0 -2
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
- package/dist/api/RootComponent/index.d.ts +5 -5
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubData/SubDataConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubData/test/normal.test.js +0 -15
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubEvents/test/normal.test.js +20 -0
- package/dist/api/SubComponent/SubEvents/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +3 -2
- package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +3 -0
- package/dist/api/SubComponent/SubInherit/SubInheritOption.js +2 -0
- package/dist/api/SubComponent/SubInherit/SubInheritOption.js.map +1 -0
- package/dist/api/SubComponent/SubInherit/test/error.test.js +1 -1
- package/dist/api/SubComponent/SubInherit/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubInherit/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +3 -2
- package/dist/api/SubComponent/SubMethods/test/error.test.js +6 -0
- package/dist/api/SubComponent/SubMethods/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubMethods/test/normarl.test.js +3 -3
- package/dist/api/SubComponent/SubMethods/test/normarl.test.js.map +1 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.d.ts +0 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js +1 -11
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.d.ts +0 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js +1 -25
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubStore/SubDataConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +1 -1
- package/dist/api/SubComponent/SubStore/test/error.test.js +2 -0
- package/dist/api/SubComponent/SubStore/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubStore/test/normal.test.js +1 -0
- package/dist/api/SubComponent/SubStore/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/SubWatchOption.d.ts +2 -1
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.d.ts +1 -0
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js +44 -1
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/test/error.test.js +10 -2
- package/dist/api/SubComponent/SubWatch/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/index.d.ts +3 -4
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/types.d.ts +1 -0
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/behaviors/BbeforeCreated.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/OfficialTypeAlias.d.ts +1 -1
- package/dist/types/RemoveInnerData.d.ts +1 -0
- package/dist/types/RemoveInnerData.js +2 -0
- package/dist/types/RemoveInnerData.js.map +1 -0
- package/package.json +4 -2
- package/src/api/DefineComponent/collectOptionsForComponent.ts +99 -16
- package/src/api/DefineComponent/index.ts +2 -2
- package/src/api/RootComponent/Computed/ComputedOption.ts +23 -3
- package/src/api/RootComponent/Computed/GetComputedDoc.ts +1 -3
- package/src/api/RootComponent/Computed/test/normal.test.ts +9 -19
- package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +26 -22
- package/src/api/RootComponent/CustomEvents/test/error.test.ts +5 -5
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Data/DataConstraint.ts +1 -1
- package/src/api/RootComponent/Data/DataOption.ts +6 -4
- package/src/api/RootComponent/Data/GetDataDoc.ts +1 -18
- package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +14 -25
- package/src/api/RootComponent/Data/test/error.test.ts +2 -2
- package/src/api/RootComponent/Data/test/normal.test.ts +5 -8
- package/src/api/RootComponent/Events/EventsConstraint.ts +24 -19
- package/src/api/RootComponent/Events/EventsOption.ts +54 -6
- package/src/api/RootComponent/Events/test/normal.test.ts +16 -16
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +1 -1
- package/src/api/RootComponent/IsPage/IsPageOption.ts +1 -1
- package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +11 -8
- package/src/api/RootComponent/Lifetimes/LifetimesOption.ts +26 -0
- package/src/api/RootComponent/Lifetimes/test/error.test.ts +3 -13
- package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Methods/MethodsOption.ts +3 -0
- package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +21 -10
- package/src/api/RootComponent/PageLifetimes/test/error.test.ts +7 -5
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +9 -10
- package/src/api/RootComponent/Properties/PropertiesOption.ts +19 -32
- package/src/api/RootComponent/RootComponentDoc.ts +19 -3
- package/src/api/RootComponent/Store/GeTStoreDoc.ts +1 -1
- package/src/api/RootComponent/Store/StoreOption.ts +14 -2
- package/src/api/RootComponent/Store/test/error.test.ts +5 -5
- package/src/api/RootComponent/Store/test/normal.test.ts +1 -0
- package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +1 -12
- package/src/api/RootComponent/index.ts +13 -15
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +0 -1
- package/src/api/SubComponent/SubData/SubDataConstraint.ts +2 -3
- package/src/api/SubComponent/SubData/SubDataOption.ts +4 -0
- package/src/api/SubComponent/SubData/test/error.test.ts +1 -1
- package/src/api/SubComponent/SubData/test/normal.test.ts +6 -37
- package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +7 -2
- package/src/api/SubComponent/SubEvents/SubEventsOptions.ts +7 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +5 -4
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +31 -4
- package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +6 -3
- package/src/api/SubComponent/SubInherit/SubInheritOption.ts +8 -0
- package/src/api/SubComponent/SubInherit/test/error.test.ts +9 -7
- package/src/api/SubComponent/SubInherit/test/normal.test.ts +5 -4
- package/src/api/SubComponent/SubMethods/SubMethodsOption.ts +7 -3
- package/src/api/SubComponent/SubMethods/test/error.test.ts +13 -5
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +6 -12
- package/src/api/SubComponent/SubPageLifetimes/test/error.test.ts +1 -32
- package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +1 -74
- package/src/api/SubComponent/SubStore/SubDataConstraint.ts +2 -2
- package/src/api/SubComponent/SubStore/SubStoreOption.ts +15 -1
- package/src/api/SubComponent/SubStore/test/error.test.ts +4 -0
- package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -0
- package/src/api/SubComponent/SubWatch/SubWatchOption.ts +2 -1
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +75 -43
- package/src/api/SubComponent/SubWatch/test/error.test.ts +12 -3
- package/src/api/SubComponent/index.ts +9 -5
- package/src/behaviors/BComputedAndWatch/index.ts +2 -2
- package/src/behaviors/BComputedAndWatch/types.ts +1 -0
- package/src/behaviors/BStore.ts +2 -2
- package/src/behaviors/BbeforeCreated.ts +2 -2
- package/src/index.ts +9 -1
- package/src/types/OfficialTypeAlias.ts +7 -11
- package/src/types/RemoveInnerData.ts +5 -0
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
|
|
3
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
4
|
-
import { RootComponent } from "../..";
|
|
5
|
-
|
|
6
3
|
import type { DetailedType } from "../../../..";
|
|
7
|
-
|
|
8
|
-
// type Mock_Cart,
|
|
9
|
-
// mock_requiredTypes,
|
|
10
|
-
// mock_requiredUnion,
|
|
11
|
-
// type Mock_User,
|
|
12
|
-
// } from "../../Properties/expected/normalRequired";
|
|
4
|
+
import { RootComponent } from "../..";
|
|
13
5
|
import type { OptionalType } from "../../Properties/PropertiesConstraint";
|
|
14
6
|
import {
|
|
15
7
|
type Mock_Cart,
|
|
@@ -155,8 +147,5 @@ RootComponent()({
|
|
|
155
147
|
|
|
156
148
|
Checking<string, typeof oldValue, Test.Pass>;
|
|
157
149
|
},
|
|
158
|
-
|
|
159
|
-
"optional_objOrNull.age"() {
|
|
160
|
-
},
|
|
161
150
|
},
|
|
162
151
|
});
|
|
@@ -26,13 +26,12 @@ import type { PageLifetimesOption } from "./PageLifetimes/PageLifetimesOption";
|
|
|
26
26
|
import type { GetPropertiesDoc } from "./Properties/GetPropertiesDoc";
|
|
27
27
|
import type { PropertiesConstraint } from "./Properties/PropertiesConstraint";
|
|
28
28
|
import type { PropertiesOption } from "./Properties/PropertiesOption";
|
|
29
|
-
import type {
|
|
29
|
+
import type { GetStoreDoc } from "./Store/GeTStoreDoc";
|
|
30
30
|
import type { StoreConstraint } from "./Store/StoreConstraint";
|
|
31
31
|
import type { StoreOption } from "./Store/StoreOption";
|
|
32
32
|
import type { WatchOption } from "./Watch/WatchOption";
|
|
33
33
|
|
|
34
34
|
type RootComponentOptions<
|
|
35
|
-
TReceivedComponentDoc extends object,
|
|
36
35
|
TEvents extends object,
|
|
37
36
|
TIsPage extends boolean,
|
|
38
37
|
TCustomEvents extends CustomEventConstraint,
|
|
@@ -51,11 +50,11 @@ type RootComponentOptions<
|
|
|
51
50
|
& MethodsOption<TMethods, keyof (EventsDoc & CustomEventsDoc)>
|
|
52
51
|
& PropertiesOption<TProperties>
|
|
53
52
|
& IsPageOption<TIsPage>
|
|
54
|
-
&
|
|
55
|
-
&
|
|
56
|
-
& DataOption<TData, PropertiesDoc>
|
|
57
|
-
& StoreOption<TStore, PropertiesDoc & DataDoc>
|
|
58
|
-
& ComputedOption<TComputed,
|
|
53
|
+
& EventsOption<TEvents>
|
|
54
|
+
& CustomEventsOption<TCustomEvents, keyof EventsDoc>
|
|
55
|
+
& DataOption<TData, keyof PropertiesDoc>
|
|
56
|
+
& StoreOption<TStore, keyof (PropertiesDoc & DataDoc)>
|
|
57
|
+
& ComputedOption<TComputed, keyof (PropertiesDoc & DataDoc & StoreDoc)>
|
|
59
58
|
& PageLifetimesOption<TIsPage, NoInfer<PropertiesDoc>>
|
|
60
59
|
& LifetimesOption<TIsPage>
|
|
61
60
|
& WatchOption<
|
|
@@ -76,10 +75,10 @@ type RootComponentOptions<
|
|
|
76
75
|
>
|
|
77
76
|
>;
|
|
78
77
|
|
|
79
|
-
type RootComponentConstructor<
|
|
78
|
+
type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = {
|
|
80
79
|
<
|
|
81
80
|
// TEvents 不能有默认值 {} 会引起事件参数类型(e)失效
|
|
82
|
-
TEvents extends EventsConstraint<
|
|
81
|
+
TEvents extends EventsConstraint<TComponentDocList>,
|
|
83
82
|
TIsPage extends boolean = false,
|
|
84
83
|
const TProperties extends PropertiesConstraint = {},
|
|
85
84
|
TData extends object = {},
|
|
@@ -88,15 +87,14 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
|
|
|
88
87
|
// 页面时自定义事件无意义
|
|
89
88
|
TCustomEvents extends IfExtends<TIsPage, false, CustomEventConstraint, EmptyObject> = {},
|
|
90
89
|
TMethods extends MethodsConstraint = {},
|
|
91
|
-
EventsDoc extends object = IfExtends<EventsConstraint<
|
|
90
|
+
EventsDoc extends object = IfExtends<EventsConstraint<TComponentDocList>, TEvents, {}, TEvents>,
|
|
92
91
|
CustomEventsDoc extends object = GetCustomEventDoc<TCustomEvents>,
|
|
93
92
|
PropertiesDoc extends object = GetPropertiesDoc<TProperties, TIsPage>,
|
|
94
93
|
DataDoc extends object = TData,
|
|
95
|
-
StoreDoc extends object =
|
|
94
|
+
StoreDoc extends object = GetStoreDoc<TStore>,
|
|
96
95
|
ComputedDoc extends object = GetComputedDoc<TComputed>,
|
|
97
96
|
>(
|
|
98
97
|
options: RootComponentOptions<
|
|
99
|
-
TReceivedComponentDoc,
|
|
100
98
|
TEvents,
|
|
101
99
|
TIsPage,
|
|
102
100
|
TCustomEvents,
|
|
@@ -126,10 +124,10 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
|
|
|
126
124
|
};
|
|
127
125
|
|
|
128
126
|
export function RootComponent<
|
|
129
|
-
//
|
|
130
|
-
|
|
127
|
+
// TComponentDocList泛型为了给events字段提供类型约束
|
|
128
|
+
TComponentDocList extends ComponentDoc[] = [],
|
|
131
129
|
>(): RootComponentConstructor<
|
|
132
|
-
|
|
130
|
+
TComponentDocList
|
|
133
131
|
> {
|
|
134
132
|
return ((options: any) => options as RootComponentTrueOptions) as any;
|
|
135
133
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
-
import type { Wm } from "../../../../thirdLib";
|
|
4
|
-
import type { ComponentDocExtension } from "../../../../types/ComponentDocExtension";
|
|
5
3
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
6
4
|
|
|
7
5
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
@@ -15,61 +13,32 @@ type CompDoc = ComponentDoc<{
|
|
|
15
13
|
};
|
|
16
14
|
}>;
|
|
17
15
|
|
|
18
|
-
// 1 data字段的key提示为:组件文档字段去除inherit字段后的字段.值类型为:文档对应字段类型或函数返回类型(表示引入的Store数据)。或临时字段(内部运算所用字段,无法渲染到页面)key,值类型为unknown
|
|
19
16
|
SubComponent<{}, CompDoc>()({
|
|
20
17
|
inherit: {
|
|
21
18
|
aaa_obj: "wxml",
|
|
22
19
|
},
|
|
23
20
|
data: {
|
|
21
|
+
// 1. 子组件key和对应的类型。
|
|
24
22
|
aaa_str: "a",
|
|
25
23
|
aaa_num: 123,
|
|
24
|
+
// 2. 可写内部字段,一般作为公共的临时数据。
|
|
26
25
|
_aaa_template: "internal", // 内部临时数据
|
|
27
26
|
},
|
|
28
27
|
});
|
|
29
28
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
Wm.View,
|
|
33
|
-
{ properties: { view_obj: Mock_User | null; view_str: string; view_ddd: number } }
|
|
34
|
-
>;
|
|
35
|
-
|
|
36
|
-
const res = SubComponent<{}, viewExtends>()({
|
|
37
|
-
inherit: {
|
|
38
|
-
view_style: "wxml",
|
|
39
|
-
},
|
|
40
|
-
data: {
|
|
41
|
-
// view组件key
|
|
42
|
-
view_class: "h-full",
|
|
43
|
-
view_hover_class: "none",
|
|
44
|
-
// 拓展的字段
|
|
45
|
-
view_obj: {} as Mock_User | null,
|
|
46
|
-
view_str: "a",
|
|
47
|
-
view_ddd: 123,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
Checking<typeof res, never, Test.Pass>;
|
|
52
|
-
|
|
53
|
-
// 2 CompDoc去除Inherit字段后为空,可写非临时字段(内部字段)
|
|
54
|
-
SubComponent<{}, CompDoc>()({
|
|
29
|
+
//
|
|
30
|
+
SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
55
31
|
inherit: {
|
|
56
32
|
aaa_str: "wxml",
|
|
57
33
|
aaa_num: "wxml",
|
|
58
34
|
aaa_obj: "wxml",
|
|
59
35
|
},
|
|
60
36
|
data: {
|
|
37
|
+
// 3 CompDoc去除Inherit字段后为空时,可写内部字段
|
|
61
38
|
_aaa_str: "str",
|
|
62
39
|
},
|
|
63
40
|
});
|
|
64
41
|
|
|
65
|
-
// 3 CompDoc 为空对象时,参数为空对象,返回never
|
|
66
|
-
|
|
67
|
-
type EmptyCompDoc = ComponentDoc<{}>;
|
|
68
|
-
|
|
69
|
-
const res1 = SubComponent<{}, EmptyCompDoc>()({});
|
|
70
|
-
|
|
71
|
-
Checking<typeof res1, never, Test.Pass>;
|
|
72
|
-
|
|
73
42
|
SubComponent<{}, CompDoc>()({
|
|
74
43
|
data: {
|
|
75
44
|
aaa_str: "a",
|
|
@@ -79,7 +48,7 @@ SubComponent<{}, CompDoc>()({
|
|
|
79
48
|
},
|
|
80
49
|
methods: {
|
|
81
50
|
aaa_1() {
|
|
82
|
-
// 4 this.data
|
|
51
|
+
// 4 this.data中的data配置数据
|
|
83
52
|
Checking<
|
|
84
53
|
typeof this.data,
|
|
85
54
|
ReadonlyDeep<{
|
|
@@ -4,18 +4,23 @@ import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
|
|
|
4
4
|
import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
|
|
5
5
|
import type { Bubbles, Capture, CustomEventsTags } from "../../RootComponent/CustomEvents/CustomEventsTag";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 把组件事件类型转为函数类型,冒泡事件捕获事件会多一个加后缀(_catch)的key,表示阻止事件冒泡和捕获。
|
|
9
|
+
*/
|
|
7
10
|
export type SubEventsConstraint<
|
|
8
11
|
CompDoc extends ComponentDoc,
|
|
9
|
-
keys extends keyof CompDoc["customEvents"] = keyof CompDoc["customEvents"],
|
|
10
12
|
> = {
|
|
11
13
|
[
|
|
12
|
-
k in
|
|
14
|
+
k in keyof CompDoc["customEvents"] as Contains<CompDoc["customEvents"][k], Bubbles | Capture> extends true
|
|
15
|
+
? (k | `${k & string}_catch`)
|
|
13
16
|
: k
|
|
14
17
|
]?: (
|
|
15
18
|
e: IfExtends<
|
|
19
|
+
// 有可能是基础组件(手写类型),所以事件类型可能为WMBaseEvent
|
|
16
20
|
WMBaseEvent,
|
|
17
21
|
CompDoc["customEvents"][k],
|
|
18
22
|
WMBaseEvent,
|
|
23
|
+
// 去除 CustomEventsTags 标记
|
|
19
24
|
Detail<Exclude<CompDoc["customEvents"][k], CustomEventsTags>>
|
|
20
25
|
>,
|
|
21
26
|
) => void;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
|
|
3
|
-
export type SubEventsOption<TSubEvents, SubEventsDoc extends object,
|
|
3
|
+
export type SubEventsOption<TSubEvents, SubEventsDoc extends object, legalKeys extends PropertyKey> = {
|
|
4
|
+
/**
|
|
5
|
+
* 子组件事件(基础事件|自定义事件)
|
|
6
|
+
* 可使用内部泛型(Detail、Mark、WMBaseEvent、WMCustomEvent、CurrentTargetDataset、TargetDataset)自定义事件类型
|
|
7
|
+
* 非法字段检测(除了组件事件的key均属于非法字段)
|
|
8
|
+
*/
|
|
4
9
|
events?:
|
|
5
10
|
& TSubEvents
|
|
6
|
-
& V.IllegalFieldValidator<SubEventsDoc,
|
|
11
|
+
& V.IllegalFieldValidator<SubEventsDoc, legalKeys>;
|
|
7
12
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
2
|
+
import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
2
3
|
import { SubComponent } from "../..";
|
|
3
4
|
|
|
4
5
|
type CompDoc = ComponentDoc<{
|
|
@@ -17,16 +18,16 @@ SubComponent<{}, CompDoc>()({
|
|
|
17
18
|
|
|
18
19
|
type CompDoc1 = ComponentDoc<{
|
|
19
20
|
customEvents: {
|
|
20
|
-
aaa_str: string;
|
|
21
|
+
aaa_str: string | Bubbles;
|
|
21
22
|
};
|
|
22
23
|
}>;
|
|
23
24
|
|
|
24
|
-
// 组件文档有自定义事件时,events下的字段仅可写文档包含字段
|
|
25
|
+
// 非法字段检测 组件文档有自定义事件时,events下的字段仅可写文档包含字段
|
|
25
26
|
SubComponent<{}, CompDoc1>()({
|
|
26
27
|
events: {
|
|
27
|
-
aaa_str(e) {
|
|
28
|
+
aaa_str(e) { // ok
|
|
28
29
|
e;
|
|
29
|
-
},
|
|
30
|
+
},
|
|
30
31
|
// @ts-expect-error 非法字段
|
|
31
32
|
aaa_other() {},
|
|
32
33
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { Wm } from "../../../../thirdLib";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import type { Detail, Mark, WMBaseEvent } from "../../../..";
|
|
4
5
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
5
6
|
import type {
|
|
6
7
|
Bubbles,
|
|
@@ -10,6 +11,7 @@ import type {
|
|
|
10
11
|
Capture,
|
|
11
12
|
CaptureComposed,
|
|
12
13
|
} from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
14
|
+
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
13
15
|
import { SubComponent } from "../..";
|
|
14
16
|
|
|
15
17
|
type CompDoc = ComponentDoc<{
|
|
@@ -51,13 +53,13 @@ const sub1 = SubComponent<{}, CompDoc>()({
|
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
|
|
54
|
-
// 1.2 Composed事件会被返回
|
|
55
56
|
type Sub1Expected = {
|
|
56
57
|
BubblesComposed: string | BubblesComposed;
|
|
57
58
|
CapturePhaseComposed: string | CaptureComposed;
|
|
58
59
|
BubblesCapturePhaseComposed: string | BubblesCaptureComposed;
|
|
59
60
|
};
|
|
60
61
|
|
|
62
|
+
// 1.2 Composed事件会被返回
|
|
61
63
|
Checking<typeof sub1, Sub1Expected, Test.Pass>;
|
|
62
64
|
|
|
63
65
|
// 2.1 key可写入后缀字段(_catch,表示阻止冒泡和捕获事件)。
|
|
@@ -75,7 +77,6 @@ const sub2 = SubComponent<{}, CompDoc>()({
|
|
|
75
77
|
// 2.2 返回没有被加后最(_catch)的Composed事件
|
|
76
78
|
Checking<typeof sub2, { BubblesCapturePhaseComposed: string | BubblesCaptureComposed }, Test.Pass>;
|
|
77
79
|
|
|
78
|
-
// 2.3 key可写入后缀字段(_catch,表示阻止冒泡和捕获事件)。
|
|
79
80
|
const sub3 = SubComponent<{}, CompDoc>()({
|
|
80
81
|
events: {
|
|
81
82
|
aaa_BubblesComposed_catch(e) {
|
|
@@ -106,7 +107,7 @@ SubComponent<{}, Wm.View>()({
|
|
|
106
107
|
},
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
// 3.
|
|
110
|
+
// 3.1 基础组件自定义事件参数为Detail<object>
|
|
110
111
|
SubComponent<{}, Wm.ScrollView>()({
|
|
111
112
|
events: {
|
|
112
113
|
scrollView_bindscroll(e) {
|
|
@@ -126,3 +127,29 @@ SubComponent<{}, Wm.ScrollView>()({
|
|
|
126
127
|
// ...
|
|
127
128
|
},
|
|
128
129
|
});
|
|
130
|
+
|
|
131
|
+
// 4 可为事件自定义类型
|
|
132
|
+
SubComponent<{}, Wm.View>()({
|
|
133
|
+
events: {
|
|
134
|
+
view_tap(e: Detail<number>) {
|
|
135
|
+
Checking<typeof e.detail, number, Test.Pass>;
|
|
136
|
+
},
|
|
137
|
+
view_longtap(e: Mark<Mock_User>) {
|
|
138
|
+
Checking<typeof e.mark, Mock_User, Test.Pass>;
|
|
139
|
+
},
|
|
140
|
+
// ...
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// 4 可为事件自定义类型
|
|
145
|
+
SubComponent<{}, Wm.View>()({
|
|
146
|
+
events: {
|
|
147
|
+
view_tap(e: Detail<number>) {
|
|
148
|
+
Checking<typeof e.detail, number, Test.Pass>;
|
|
149
|
+
},
|
|
150
|
+
view_longtap(e: Mark<Mock_User>) {
|
|
151
|
+
Checking<typeof e.mark, Mock_User, Test.Pass>;
|
|
152
|
+
},
|
|
153
|
+
// ...
|
|
154
|
+
},
|
|
155
|
+
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { SelectKeys } from "hry-types/src/Object/_api";
|
|
2
|
+
import type { RemoveInnerData } from "../../../types/RemoveInnerData";
|
|
2
3
|
import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
|
|
3
4
|
|
|
4
5
|
type WXMLSign = "wxml";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* 子组件inherit字段约束,
|
|
8
|
+
* 子组件inherit字段约束,key为子组件所需key,根组件数据的key或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
|
|
8
9
|
* @returns object
|
|
9
10
|
*/
|
|
10
|
-
export type InheritConstraint<
|
|
11
|
-
[k in keyof TComponentDoc["properties"]]?:
|
|
11
|
+
export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentDoc> = {
|
|
12
|
+
[k in keyof TComponentDoc["properties"]]?:
|
|
13
|
+
| RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>
|
|
14
|
+
| WXMLSign;
|
|
12
15
|
};
|
|
@@ -17,6 +17,8 @@ type Mock_RootDoc = RootComponentDoc<{
|
|
|
17
17
|
str: string;
|
|
18
18
|
literal_str: "a" | "b" | "c";
|
|
19
19
|
bool: boolean;
|
|
20
|
+
_num: number;
|
|
21
|
+
_str: string;
|
|
20
22
|
};
|
|
21
23
|
computed: {
|
|
22
24
|
Cuinon: string | boolean;
|
|
@@ -34,19 +36,19 @@ type Mock_CompDoc = ComponentDoc<{
|
|
|
34
36
|
};
|
|
35
37
|
}>;
|
|
36
38
|
|
|
37
|
-
//
|
|
39
|
+
// 1 继承字段类型错误
|
|
38
40
|
SubComponent<Mock_RootDoc, Mock_CompDoc>()({
|
|
39
41
|
inherit: {
|
|
40
|
-
// @ts-expect-error
|
|
42
|
+
// @ts-expect-error 1.1 [string | number] 不是 [number] 的子集
|
|
41
43
|
aaa_num: "unionStrNum",
|
|
42
|
-
// @ts-expect-error
|
|
44
|
+
// @ts-expect-error 1.2 [123 | 456 | 789] 不是 [123 | 456] 的子集
|
|
43
45
|
aaa_literal_num: "optional_literal_num",
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
aaa_str: ""
|
|
46
|
+
// @ts-expect-error 1.3 不可继承内部字段
|
|
47
|
+
aaa_str: "_str",
|
|
46
48
|
},
|
|
47
49
|
});
|
|
48
50
|
|
|
49
|
-
// inherit
|
|
51
|
+
// 2 inherit字段最终不会在组件配置中,意义在于通过声明继承字段便于类型判断,配置是否满足子组件文档的需求。下面示例中,配置不满足组件需求,Mock_CompDoc需要一些必传字段没有配置,即使这些字段存在在于根组件(或wmxl).而返回的字符串(错误),无法通过DefinedComponent Api 类型检测。
|
|
50
52
|
const subDoc = SubComponent<Mock_RootDoc, Mock_CompDoc>()({
|
|
51
53
|
data: {
|
|
52
54
|
aaa_num: 123,
|
|
@@ -57,6 +59,6 @@ Checking<typeof subDoc, SubComponentDoc, Test.Fail>;
|
|
|
57
59
|
|
|
58
60
|
DefineComponent({
|
|
59
61
|
name: "xxx",
|
|
60
|
-
// @ts-expect-error 不能将类型“string”分配给类型“_SubComponentDoc”。
|
|
62
|
+
// @ts-expect-error 2 不能将类型“string”分配给类型“_SubComponentDoc”。
|
|
61
63
|
subComponents: [subDoc],
|
|
62
64
|
});
|
|
@@ -2,13 +2,16 @@ import type { ComponentDoc } from "../../../DefineComponent/ReturnType/Component
|
|
|
2
2
|
import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
|
|
3
3
|
import { SubComponent } from "../..";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* inherit字段最终会在选项中删除,它用ts开发类型检测。
|
|
7
|
+
*/
|
|
5
8
|
type Mock_RootDoc = RootComponentDoc<{
|
|
6
9
|
properties: {
|
|
7
10
|
required_num: number;
|
|
8
11
|
optional_literal_num?: 123 | 456 | 789;
|
|
9
12
|
unionStrNum: string | number;
|
|
10
13
|
required_obj: object | null;
|
|
11
|
-
optional_obj?: object;
|
|
14
|
+
optional_obj?: object | null;
|
|
12
15
|
};
|
|
13
16
|
data: {
|
|
14
17
|
str: string;
|
|
@@ -31,7 +34,7 @@ type Mock_CompDoc = ComponentDoc<{
|
|
|
31
34
|
};
|
|
32
35
|
}>;
|
|
33
36
|
|
|
34
|
-
// 1 没有可继承的数据,类型可为'wxml',表示数据来自wxml(
|
|
37
|
+
// 1 没有可继承的数据,类型可为'wxml',表示数据来自wxml(例如数据来自父元素循环wx:for后的数据等情况)
|
|
35
38
|
SubComponent<{}, Mock_CompDoc>()({
|
|
36
39
|
inherit: {
|
|
37
40
|
aaa_num: "wxml",
|
|
@@ -51,5 +54,3 @@ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
|
|
|
51
54
|
aaa_obj1: "" as "required_obj" | "optional_obj" | "wxml",
|
|
52
55
|
},
|
|
53
56
|
});
|
|
54
|
-
|
|
55
|
-
// inherit字段最终会在配置对象中删除,它用类型检测。
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
import type { PrefixValidator } from "hry-types/src/Generic/PrefixValidator";
|
|
3
|
+
import type { SubMethodsConstraint } from "./SubMethodsConstraint";
|
|
3
4
|
|
|
4
5
|
export type SubMethodsOption<
|
|
5
|
-
TSubMethods extends
|
|
6
|
+
TSubMethods extends SubMethodsConstraint,
|
|
6
7
|
TPrefix extends string,
|
|
7
|
-
|
|
8
|
+
ExcludedKeys extends PropertyKey,
|
|
8
9
|
> = {
|
|
10
|
+
/**
|
|
11
|
+
* 前缀检测和重复检测(与events和组件customEvents字段)
|
|
12
|
+
*/
|
|
9
13
|
methods?:
|
|
10
14
|
& TSubMethods
|
|
11
15
|
& PrefixValidator<TSubMethods, TPrefix>
|
|
12
|
-
& V.DuplicateFieldValidator<TSubMethods,
|
|
16
|
+
& V.DuplicateFieldValidator<TSubMethods, ExcludedKeys>;
|
|
13
17
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
2
|
+
import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
2
3
|
import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
|
|
3
4
|
import { SubComponent } from "../..";
|
|
4
5
|
|
|
@@ -16,22 +17,29 @@ type RootDoc = RootComponentDoc<{
|
|
|
16
17
|
|
|
17
18
|
type CompDoc = ComponentDoc<{
|
|
18
19
|
customEvents: {
|
|
19
|
-
aaa_str: string;
|
|
20
|
+
aaa_str: string | Bubbles;
|
|
20
21
|
};
|
|
21
22
|
}>;
|
|
22
23
|
|
|
23
|
-
// 前缀错误
|
|
24
|
+
// 1 前缀错误
|
|
24
25
|
SubComponent<RootDoc, CompDoc>()({
|
|
25
26
|
methods: {
|
|
26
|
-
// @ts-expect-error 前缀错误
|
|
27
|
+
// @ts-expect-error 1.1 前缀错误
|
|
27
28
|
xxx_yyy() {},
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
//
|
|
32
|
+
// 2 重复检测
|
|
32
33
|
SubComponent<RootDoc, CompDoc>()({
|
|
34
|
+
events: {
|
|
35
|
+
aaa_str_catch() {
|
|
36
|
+
},
|
|
37
|
+
},
|
|
33
38
|
methods: {
|
|
34
|
-
// @ts-expect-error
|
|
39
|
+
// @ts-expect-error 2.1 与组件自定义事件字段重复
|
|
35
40
|
aaa_str() {},
|
|
41
|
+
// @ts-expect-error 2.2 与events字段重复
|
|
42
|
+
aaa_str_catch() {
|
|
43
|
+
},
|
|
36
44
|
},
|
|
37
45
|
});
|
|
@@ -6,12 +6,6 @@ type RootDoc = RootComponentDoc<{
|
|
|
6
6
|
methods: {
|
|
7
7
|
Mstr: () => string;
|
|
8
8
|
};
|
|
9
|
-
events: {
|
|
10
|
-
Estr: () => string;
|
|
11
|
-
};
|
|
12
|
-
customEvents: {
|
|
13
|
-
Cstr: string;
|
|
14
|
-
};
|
|
15
9
|
}>;
|
|
16
10
|
|
|
17
11
|
type CompDoc = ComponentDoc<{
|
|
@@ -20,12 +14,7 @@ type CompDoc = ComponentDoc<{
|
|
|
20
14
|
};
|
|
21
15
|
}>;
|
|
22
16
|
|
|
23
|
-
//
|
|
24
|
-
SubComponent<RootDoc, CompDoc>()({
|
|
25
|
-
methods: {},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// methods字段可以写 任意字段函数,不与RootDoc和CompDoc中的方法字段重复即可,前缀为CompDoc的前缀
|
|
17
|
+
// methods字段同组件前缀
|
|
29
18
|
SubComponent<RootDoc, CompDoc>()({
|
|
30
19
|
methods: {
|
|
31
20
|
aaa_xxx() {},
|
|
@@ -33,3 +22,8 @@ SubComponent<RootDoc, CompDoc>()({
|
|
|
33
22
|
// ...
|
|
34
23
|
},
|
|
35
24
|
});
|
|
25
|
+
|
|
26
|
+
// 2 默认可以为{}。
|
|
27
|
+
SubComponent<RootDoc, CompDoc>()({
|
|
28
|
+
methods: {},
|
|
29
|
+
});
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { SubComponent } from "../..";
|
|
3
|
-
|
|
4
|
-
type RootDocCompPage = RootComponentDoc<{
|
|
5
|
-
isPage: true;
|
|
6
|
-
}>;
|
|
7
|
-
|
|
8
|
-
type CompDoc = RootComponentDoc<{
|
|
9
|
-
properties: {
|
|
10
|
-
aaa_str: string;
|
|
11
|
-
};
|
|
12
|
-
}>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 测试 组件时
|
|
16
|
-
*/
|
|
17
|
-
SubComponent<{}, CompDoc>()({
|
|
18
|
-
pageLifetimes: {
|
|
19
|
-
// @ts-expect-error 不存在的字段 show是正确字段
|
|
20
|
-
onShow() {},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 页面时
|
|
26
|
-
*/
|
|
27
|
-
SubComponent<RootDocCompPage, CompDoc>()({
|
|
28
|
-
pageLifetimes: {
|
|
29
|
-
// @ts-expect-error 不存在的字段 多了一个 `d`
|
|
30
|
-
onLoadd() {},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
1
|
+
// 同 RootComponent的PageLifetimes
|