annil 1.12.7 → 1.13.1
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 +22 -0
- package/dist/api/ChunkComponent/ChunkStore/ChunkStoreOption.d.ts +2 -1
- package/dist/api/ChunkComponent/index.d.ts +3 -3
- package/dist/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.d.ts +1 -1
- package/dist/api/CustomComponent/CustomStore/CustomStoreConstraint.d.ts +3 -2
- package/dist/api/CustomComponent/CustomStore/CustomStoreOption.d.ts +1 -3
- package/dist/api/CustomComponent/index.d.ts +4 -3
- package/dist/api/CustomComponent/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js +4 -19
- package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js.map +1 -1
- package/dist/api/RootComponent/Computed/{GetComputedDoc.d.ts → GetComputedDef.d.ts} +1 -1
- package/dist/api/RootComponent/Computed/GetComputedDef.js +2 -0
- package/dist/api/RootComponent/Computed/GetComputedDef.js.map +1 -0
- package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +10 -5
- package/dist/api/RootComponent/CustomEvents/CustomEventsTag.d.ts +2 -2
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.d.ts +10 -0
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.js +2 -0
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.js.map +1 -0
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +2 -2
- package/dist/api/RootComponent/Instance/CustomEventMethods.d.ts +2 -2
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +1 -1
- package/dist/api/RootComponent/Properties/{GetOptionalDoc.d.ts → GetOptionalDef.d.ts} +1 -1
- package/dist/api/RootComponent/Properties/GetOptionalDef.js +2 -0
- package/dist/api/RootComponent/Properties/GetOptionalDef.js.map +1 -0
- package/dist/api/RootComponent/Properties/GetPropertiesDef.d.ts +8 -0
- package/dist/api/RootComponent/Properties/GetPropertiesDef.js +2 -0
- package/dist/api/RootComponent/Properties/GetPropertiesDef.js.map +1 -0
- package/dist/api/RootComponent/Properties/GetRequiredDef.d.ts +5 -0
- package/dist/api/RootComponent/Properties/GetRequiredDef.js +2 -0
- package/dist/api/RootComponent/Properties/GetRequiredDef.js.map +1 -0
- package/dist/api/RootComponent/Store/{GeTStoreDoc.d.ts → GetStoreDef.d.ts} +1 -1
- package/dist/api/RootComponent/Store/GetStoreDef.js +3 -0
- package/dist/api/RootComponent/Store/GetStoreDef.js.map +1 -0
- package/dist/api/RootComponent/Store/StoreConstraint.d.ts +1 -5
- package/dist/api/RootComponent/Store/StoreOption.d.ts +1 -12
- package/dist/api/RootComponent/index.d.ts +19 -19
- package/dist/api/wxSugar.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js.map +1 -1
- package/dist/thirdLib/vant/Popup.d.ts +1 -1
- package/dist/thirdLib/wm/Textarea.d.ts +1 -1
- package/dist/thirdLib/wm/swiper.d.ts +1 -1
- package/dist/types/AddNullForObject.d.ts +2 -0
- package/dist/types/AddNullForObject.js +2 -0
- package/dist/types/AddNullForObject.js.map +1 -0
- package/dist/types/ComputeObject.js +2 -0
- package/dist/types/ComputeObject.js.map +1 -0
- package/dist/types/Replace.d.ts +8 -0
- package/dist/types/Replace.js +2 -0
- package/dist/types/Replace.js.map +1 -0
- package/dist/utils/nonNullable.d.ts +1 -1
- package/dist/utils/nonNullable.js +2 -2
- package/dist/utils/nonNullable.js.map +1 -1
- package/dist/utils/typeEqual.d.ts +1 -1
- package/dist/utils/typeEqual.js +2 -2
- package/dist/utils/typeEqual.js.map +1 -1
- package/package.json +1 -1
- package/src/api/ChunkComponent/ChunkComputed/test/normal.test.ts +1 -1
- package/src/api/ChunkComponent/ChunkStore/ChunkStoreOption.ts +2 -1
- package/src/api/ChunkComponent/ChunkStore/test/error.test.ts +3 -31
- package/src/api/ChunkComponent/ChunkStore/test/normal.test.ts +40 -41
- package/src/api/ChunkComponent/index.ts +4 -4
- package/src/api/CustomComponent/CustomData/test/normal.test.ts +7 -4
- package/src/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.ts +1 -1
- package/src/api/CustomComponent/CustomStore/CustomStoreConstraint.ts +3 -2
- package/src/api/CustomComponent/CustomStore/CustomStoreOption.ts +0 -2
- package/src/api/CustomComponent/CustomStore/test/error.test.ts +6 -46
- package/src/api/CustomComponent/CustomStore/test/normal.test.ts +0 -45
- package/src/api/CustomComponent/index.ts +7 -6
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +4 -4
- package/src/api/DefineComponent/index.ts +4 -4
- package/src/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.ts +5 -20
- package/src/api/DefineComponent/returnType/test/normalPageDoc.test.ts +0 -1
- package/src/api/RootComponent/Computed/ComputedOption.ts +2 -3
- package/src/api/RootComponent/Computed/{GetComputedDoc.ts → GetComputedDef.ts} +1 -1
- package/src/api/RootComponent/Computed/test/GetComputedDoc.test.ts +3 -3
- package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +20 -5
- package/src/api/RootComponent/CustomEvents/CustomEventsDef.ts +4 -0
- package/src/api/RootComponent/CustomEvents/CustomEventsTag.ts +2 -2
- package/src/api/RootComponent/CustomEvents/GetCustomEventDef.ts +29 -0
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +3 -3
- package/src/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.ts +2 -2
- package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +6 -6
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +8 -8
- package/src/api/RootComponent/Data/GetDataDef.ts +8 -0
- package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +3 -3
- package/src/api/RootComponent/Events/EventsConstraint.ts +3 -3
- package/src/api/RootComponent/Events/EventsOption.ts +2 -2
- package/src/api/RootComponent/Events/test/normal.test.ts +16 -0
- package/src/api/RootComponent/Instance/CustomEventMethods.ts +4 -4
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -4
- package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +1 -1
- package/src/api/RootComponent/Properties/{GetOptionalDoc.ts → GetOptionalDef.ts} +1 -1
- package/src/api/RootComponent/Properties/GetPropertiesDef.ts +25 -0
- package/src/api/RootComponent/Properties/GetRequiredDef.ts +16 -0
- package/src/api/RootComponent/Store/{GeTStoreDoc.ts → GetStoreDef.ts} +10 -14
- package/src/api/RootComponent/Store/StoreConstraint.ts +1 -7
- package/src/api/RootComponent/Store/StoreOption.ts +6 -40
- package/src/api/RootComponent/Store/test/error.test.ts +3 -38
- package/src/api/RootComponent/Store/test/normal.test.ts +0 -46
- package/src/api/RootComponent/index.ts +50 -50
- package/src/api/wxSugar.ts +1 -1
- package/src/index.ts +1 -2
- package/src/thirdLib/vant/Popup.ts +1 -1
- package/src/thirdLib/wm/Textarea.ts +1 -1
- package/src/thirdLib/wm/swiper.test.ts +22 -0
- package/src/thirdLib/wm/swiper.ts +1 -1
- package/src/types/CreateComponentType.ts +2 -2
- package/src/types/ExtendComponentType.ts +5 -5
- package/src/utils/nonNullable.ts +4 -1
- package/src/utils/typeEqual.ts +11 -8
- package/src/utils/typeNotEqual.ts +48 -0
- package/dist/api/RootComponent/Computed/GetComputedDoc.js +0 -2
- package/dist/api/RootComponent/Computed/GetComputedDoc.js.map +0 -1
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +0 -10
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.js +0 -2
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.js.map +0 -1
- package/dist/api/RootComponent/Properties/GetOptionalDoc.js +0 -2
- package/dist/api/RootComponent/Properties/GetOptionalDoc.js.map +0 -1
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +0 -8
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.js +0 -2
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.js.map +0 -1
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +0 -6
- package/dist/api/RootComponent/Properties/GetRequiredDoc.js +0 -2
- package/dist/api/RootComponent/Properties/GetRequiredDoc.js.map +0 -1
- package/dist/api/RootComponent/Store/GeTStoreDoc.js +0 -2
- package/dist/api/RootComponent/Store/GeTStoreDoc.js.map +0 -1
- package/dist/types/ComputeObj.js +0 -2
- package/dist/types/ComputeObj.js.map +0 -1
- package/dist/types/TwoParamsEqual.d.ts +0 -2
- package/dist/types/TwoParamsEqual.js +0 -2
- package/dist/types/TwoParamsEqual.js.map +0 -1
- package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +0 -24
- package/src/api/RootComponent/Properties/GetRequiredDoc.ts +0 -23
- /package/dist/types/{ComputeObj.d.ts → ComputeObject.d.ts} +0 -0
- /package/src/types/{ComputeObj.ts → ComputeObject.ts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
2
2
|
import { Checking, type Test } from "hry-types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GetComputedDef } from "../GetComputedDef";
|
|
4
4
|
|
|
5
5
|
// test1 非空对象字段
|
|
6
6
|
|
|
7
|
-
type Test1 =
|
|
7
|
+
type Test1 = GetComputedDef<{
|
|
8
8
|
a: () => number;
|
|
9
9
|
b: () => string;
|
|
10
10
|
c: () => "male" | "femal";
|
|
@@ -20,6 +20,6 @@ Checking<Test1, Test1Expected, Test.Pass>;
|
|
|
20
20
|
|
|
21
21
|
// test2 空对象字段 返回空
|
|
22
22
|
|
|
23
|
-
type Test2 =
|
|
23
|
+
type Test2 = GetComputedDef<{}>;
|
|
24
24
|
|
|
25
25
|
Checking<Test2, {}, Test.Pass>;
|
|
@@ -42,33 +42,48 @@ export type OptionsFieldsConfigOfCustomEvents =
|
|
|
42
42
|
/**
|
|
43
43
|
* 带options的CustomEvents配置
|
|
44
44
|
*/
|
|
45
|
-
export type
|
|
45
|
+
export type FullCustomEventsOptions = {
|
|
46
46
|
detail: ShortCustomeEvents;
|
|
47
47
|
options: OptionsFieldsConfigOfCustomEvents;
|
|
48
48
|
debounce?: never;
|
|
49
49
|
throttle?: never;
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type FullCustomEventsWithDebounce = {
|
|
51
53
|
detail: ShortCustomeEvents;
|
|
52
54
|
options?: never;
|
|
53
55
|
debounce: number;
|
|
54
56
|
throttle?: never;
|
|
55
|
-
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type FullCustomEventsWithThrottle = {
|
|
56
60
|
detail: ShortCustomeEvents;
|
|
57
61
|
options?: never;
|
|
58
62
|
debounce?: never;
|
|
59
63
|
throttle: number;
|
|
60
|
-
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type FullCustomEventsOptionsWithThrottle = {
|
|
61
67
|
detail: ShortCustomeEvents;
|
|
62
68
|
options: OptionsFieldsConfigOfCustomEvents;
|
|
63
69
|
debounce?: never;
|
|
64
70
|
throttle: number;
|
|
65
|
-
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type FullCustomEventsOptionsWithDebounce = {
|
|
66
74
|
detail: ShortCustomeEvents;
|
|
67
75
|
options: OptionsFieldsConfigOfCustomEvents;
|
|
68
76
|
debounce: number;
|
|
69
77
|
throttle?: never;
|
|
70
78
|
};
|
|
71
79
|
|
|
80
|
+
export type FullCustomEvents =
|
|
81
|
+
| FullCustomEventsOptions
|
|
82
|
+
| FullCustomEventsWithDebounce
|
|
83
|
+
| FullCustomEventsWithThrottle
|
|
84
|
+
| FullCustomEventsOptionsWithThrottle
|
|
85
|
+
| FullCustomEventsOptionsWithDebounce;
|
|
86
|
+
|
|
72
87
|
export type CustomEvents = FullCustomEvents | ShortCustomeEvents;
|
|
73
88
|
|
|
74
89
|
export type CustomEventConstraint = Record<string, CustomEvents>;
|
|
@@ -13,7 +13,7 @@ export type Bubbles = () => "bubbles";
|
|
|
13
13
|
|
|
14
14
|
export type Capture = () => "capture";
|
|
15
15
|
|
|
16
|
-
export type Composed = () => "
|
|
16
|
+
export type Composed = () => "composed";
|
|
17
17
|
|
|
18
18
|
export type BubblesCapture = Bubbles | Capture;
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ export type CustomEventsTags =
|
|
|
31
31
|
| CaptureComposed
|
|
32
32
|
| BubblesCaptureComposed;
|
|
33
33
|
|
|
34
|
-
export type
|
|
34
|
+
export type AddTagForCustomEventsDef<Options extends OptionsFieldsConfigOfCustomEvents> = IfExtends<
|
|
35
35
|
BubblesOption,
|
|
36
36
|
Options,
|
|
37
37
|
Bubbles,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
+
import type { DetailedType } from "../../../types/DetailedType";
|
|
3
|
+
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
4
|
+
import type {
|
|
5
|
+
CustomEventConstraint,
|
|
6
|
+
FullCustomEvents,
|
|
7
|
+
ShortCustomeEvents,
|
|
8
|
+
SimpleCustomeEventsList,
|
|
9
|
+
} from "./CustomEventConstraint";
|
|
10
|
+
import type { AddTagForCustomEventsDef } from "./CustomEventsTag";
|
|
11
|
+
|
|
12
|
+
export type GetShortCustomEventsDef<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T>
|
|
13
|
+
: T extends null ? null
|
|
14
|
+
: T extends undefined ? undefined
|
|
15
|
+
: T extends SimpleCustomeEventsList ? GetShortCustomEventsDef<T[number]>
|
|
16
|
+
: never;
|
|
17
|
+
|
|
18
|
+
export type GetFullCustomEventsDef<T extends FullCustomEvents> =
|
|
19
|
+
| GetShortCustomEventsDef<T["detail"]>
|
|
20
|
+
| IfExtends<unknown, T["options"], never, AddTagForCustomEventsDef<T["options"] & {}>>;
|
|
21
|
+
|
|
22
|
+
export type GetCustomEventsDef<T extends CustomEventConstraint> = {
|
|
23
|
+
[k in keyof T]: T[k] extends ShortCustomeEvents ? GetShortCustomEventsDef<T[k]>
|
|
24
|
+
: T[k] extends FullCustomEvents ?
|
|
25
|
+
| GetShortCustomEventsDef<T[k]["detail"]>
|
|
26
|
+
// 为事件加上标签
|
|
27
|
+
| IfExtends<unknown, T[k]["options"], never, AddTagForCustomEventsDef<NonNullable<T[k]["options"]>>>
|
|
28
|
+
: never;
|
|
29
|
+
};
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
ShortCustomeEvents,
|
|
8
8
|
SimpleCustomeEventsList,
|
|
9
9
|
} from "./CustomEventConstraint";
|
|
10
|
-
import type {
|
|
10
|
+
import type { AddTagForCustomEventsDef } from "./CustomEventsTag";
|
|
11
11
|
|
|
12
12
|
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T>
|
|
13
13
|
: T extends null ? null
|
|
@@ -17,7 +17,7 @@ export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends De
|
|
|
17
17
|
|
|
18
18
|
export type GetFullCustomEventsDoc<T extends FullCustomEvents> =
|
|
19
19
|
| GetShortCustomEventsDoc<T["detail"]>
|
|
20
|
-
| IfExtends<unknown, T["options"], never,
|
|
20
|
+
| IfExtends<unknown, T["options"], never, AddTagForCustomEventsDef<T["options"] & {}>>;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* 获取自定义事件的文档
|
|
@@ -42,6 +42,6 @@ export type GetCustomEventDoc<T extends CustomEventConstraint> =
|
|
|
42
42
|
// 为自定义事件模型加标记,方便识别
|
|
43
43
|
// @ts-ignore T[k] 一定为 FullCustomEvents 类型
|
|
44
44
|
// | AddTagForCustomEventsDoc<T[k]["options"]>;
|
|
45
|
-
| IfExtends<unknown, T[k]["options"], never,
|
|
45
|
+
| IfExtends<unknown, T[k]["options"], never, AddTagForCustomEventsDef<T[k]["options"] & {}>>;
|
|
46
46
|
}
|
|
47
47
|
;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GetCustomEventsDef } from "../GetCustomEventDef";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
type BubblesCapturePhaseComposedExpected,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "./GetShortEventDoc.test";
|
|
19
19
|
import { type mock_customEvents } from "./normal.test";
|
|
20
20
|
|
|
21
|
-
type Mock_CustomEventsDoc =
|
|
21
|
+
type Mock_CustomEventsDoc = GetCustomEventsDef<typeof mock_customEvents>;
|
|
22
22
|
|
|
23
23
|
export type Mock_CustomEventsDocExpected = {
|
|
24
24
|
str: StrExpected;
|
|
@@ -2,34 +2,34 @@
|
|
|
2
2
|
import { Checking, type Test } from "hry-types";
|
|
3
3
|
|
|
4
4
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
5
|
-
import type {
|
|
5
|
+
import type { GetShortCustomEventsDef } from "../GetCustomEventDef";
|
|
6
6
|
import { type mock_shortCustomEvents } from "./normal.test";
|
|
7
7
|
|
|
8
|
-
type StrResult =
|
|
8
|
+
type StrResult = GetShortCustomEventsDef<typeof mock_shortCustomEvents["str"]>;
|
|
9
9
|
|
|
10
10
|
export type StrExpected = string;
|
|
11
11
|
|
|
12
12
|
Checking<StrResult, StrExpected, Test.Pass>;
|
|
13
13
|
|
|
14
|
-
type NullResult =
|
|
14
|
+
type NullResult = GetShortCustomEventsDef<typeof mock_shortCustomEvents["null"]>;
|
|
15
15
|
|
|
16
16
|
export type NullExpected = null;
|
|
17
17
|
|
|
18
18
|
Checking<NullResult, NullExpected, Test.Pass>;
|
|
19
19
|
|
|
20
|
-
type UnionStrResult =
|
|
20
|
+
type UnionStrResult = GetShortCustomEventsDef<typeof mock_shortCustomEvents["unionStr"]>;
|
|
21
21
|
|
|
22
22
|
export type UnionStrExpected = "male" | "female";
|
|
23
23
|
|
|
24
24
|
Checking<UnionStrResult, UnionStrExpected, Test.Pass>;
|
|
25
25
|
|
|
26
|
-
type ListResult =
|
|
26
|
+
type ListResult = GetShortCustomEventsDef<typeof mock_shortCustomEvents["union"]>;
|
|
27
27
|
|
|
28
28
|
export type ListExpected = string | 0 | 1 | 2 | null;
|
|
29
29
|
|
|
30
30
|
Checking<ListResult, ListExpected, Test.Pass>;
|
|
31
31
|
|
|
32
|
-
type ObjResult =
|
|
32
|
+
type ObjResult = GetShortCustomEventsDef<typeof mock_shortCustomEvents["obj"]>;
|
|
33
33
|
|
|
34
34
|
export type ObjExpected = Mock_User;
|
|
35
35
|
|
|
@@ -60,11 +60,11 @@ export const mock_customEvents = {
|
|
|
60
60
|
...mock_fullCustomEvents,
|
|
61
61
|
} satisfies CustomEventConstraint;
|
|
62
62
|
|
|
63
|
-
const
|
|
63
|
+
const rootDef = RootComponent()({
|
|
64
64
|
customEvents: mock_customEvents,
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
type
|
|
67
|
+
type RootDef = {
|
|
68
68
|
customEvents: {
|
|
69
69
|
// 简写字段 值类型为事件参数e的detail类型
|
|
70
70
|
str: string;
|
|
@@ -83,17 +83,17 @@ type RootDoc = {
|
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
// 1
|
|
87
|
-
Checking<typeof
|
|
86
|
+
// 1 RootDef中customEventsDoc 类型为事件参数e的detail类型和事件标记的联合(冒泡|穿透|捕获)
|
|
87
|
+
Checking<typeof rootDef, RootDef, Test.Pass>;
|
|
88
88
|
|
|
89
|
-
const
|
|
89
|
+
const rootDefEmpty = RootComponent()({
|
|
90
90
|
customEvents: {},
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// 2. customEvents字段配置为`{}`时,Doc中无customEvents字段
|
|
94
|
-
Checking<typeof
|
|
94
|
+
Checking<typeof rootDefEmpty, {}, Test.Pass>;
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const rootDefNoFields = RootComponent()({});
|
|
97
97
|
|
|
98
98
|
// 3. 无customEvents字段时,Doc中无customEvents字段
|
|
99
|
-
Checking<typeof
|
|
99
|
+
Checking<typeof rootDefNoFields, {}, Test.Pass>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { GetDataDef } from "../GetDataDef";
|
|
4
4
|
|
|
5
5
|
export const mock_data = {
|
|
6
6
|
func: {
|
|
@@ -12,7 +12,7 @@ export const mock_data = {
|
|
|
12
12
|
str: "str",
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
type Test1 =
|
|
15
|
+
type Test1 = GetDataDef<typeof mock_data>;
|
|
16
16
|
|
|
17
17
|
type Test1Expected = {
|
|
18
18
|
func: {
|
|
@@ -25,7 +25,7 @@ type Test1Expected = {
|
|
|
25
25
|
void Checking<Test1, Test1Expected, Test.Pass>;
|
|
26
26
|
|
|
27
27
|
// 测试空对象
|
|
28
|
-
type Test4 =
|
|
28
|
+
type Test4 = GetDataDef<{}>;
|
|
29
29
|
|
|
30
30
|
type Test4Expected = {};
|
|
31
31
|
|
|
@@ -50,8 +50,8 @@ type TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<T extends CustomEven
|
|
|
50
50
|
|
|
51
51
|
// 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detail)转换为函数类型
|
|
52
52
|
type GetAllSubCustomEventsConstraint<
|
|
53
|
-
|
|
54
|
-
AllCustomEvents extends CustomEventsDoc = GetBubblesOrCaptureEventsFromCompDoc<
|
|
53
|
+
TComponentDocList extends ComponentDoc[],
|
|
54
|
+
AllCustomEvents extends CustomEventsDoc = GetBubblesOrCaptureEventsFromCompDoc<TComponentDocList>,
|
|
55
55
|
> = IfExtends<
|
|
56
56
|
{},
|
|
57
57
|
AllCustomEvents,
|
|
@@ -70,5 +70,5 @@ export type EventsConstraint<ComponentDocList extends ComponentDoc[] = []> = IfE
|
|
|
70
70
|
[],
|
|
71
71
|
ComponentDocList,
|
|
72
72
|
BaseEvent,
|
|
73
|
-
GetAllSubCustomEventsConstraint<ComponentDocList>
|
|
73
|
+
GetAllSubCustomEventsConstraint<ComponentDocList> & BaseEvent
|
|
74
74
|
>;
|
|
@@ -15,14 +15,14 @@ export type EventsOption<TEvents extends object> = {
|
|
|
15
15
|
* @example B
|
|
16
16
|
* ```ts
|
|
17
17
|
* type ComponentDocA = {
|
|
18
|
-
*
|
|
18
|
+
* events: {
|
|
19
19
|
* aaa_str: string;
|
|
20
20
|
* aaa_num: number | Bubbles;
|
|
21
21
|
* };
|
|
22
22
|
* };
|
|
23
23
|
*
|
|
24
24
|
* type ComponentDocB = {
|
|
25
|
-
*
|
|
25
|
+
* events: {
|
|
26
26
|
* bbb_str: string;
|
|
27
27
|
* bbb_num: number | Capture;
|
|
28
28
|
* };
|
|
@@ -143,3 +143,19 @@ Checking<typeof EmptyEventsFields, {}, Test.Pass>;
|
|
|
143
143
|
const NoEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({});
|
|
144
144
|
|
|
145
145
|
Checking<typeof NoEventsFields, {}, Test.Pass>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 7. 子事件可以与root事件共存。
|
|
149
|
+
*/
|
|
150
|
+
const RootDef = RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
151
|
+
events: {
|
|
152
|
+
// root事件
|
|
153
|
+
root_str(e) {
|
|
154
|
+
Checking<typeof e, WMBaseEvent, Test.Pass>;
|
|
155
|
+
},
|
|
156
|
+
// 子事件
|
|
157
|
+
aaa_num_bubbles(e) {
|
|
158
|
+
Checking<typeof e.detail, number, Test.Pass>;
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { CustomEventsTags } from "../CustomEvents/CustomEventsTag";
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
[k in keyof
|
|
6
|
-
Exclude<
|
|
4
|
+
export type generateCustomEventMethods<TCustomEventsDef extends object> = {
|
|
5
|
+
[k in keyof TCustomEventsDef]: IfExtends<
|
|
6
|
+
Exclude<TCustomEventsDef[k], CustomEventsTags>,
|
|
7
7
|
undefined,
|
|
8
8
|
() => void,
|
|
9
|
-
(detail: Exclude<
|
|
9
|
+
(detail: Exclude<TCustomEventsDef[k], CustomEventsTags>) => void
|
|
10
10
|
>;
|
|
11
11
|
};
|
|
@@ -5,18 +5,18 @@ import type { IReactionDisposer } from "mobx";
|
|
|
5
5
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
6
6
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
7
7
|
import type { Assign } from "../../../types/Assign";
|
|
8
|
-
import type { ComputeObject } from "../../../types/
|
|
8
|
+
import type { ComputeObject } from "../../../types/ComputeObject";
|
|
9
9
|
import type { WMComponentInstance, WMInstanceMethods, WMPageInstance } from "../../../types/OfficialTypeAlias";
|
|
10
10
|
import type { OptionsInnerFields } from "../../DefineComponent/normalizeOptions";
|
|
11
11
|
import type { IInjectAllData, IInjectMethods } from "../../InstanceInject/instanceConfig";
|
|
12
|
-
import type {
|
|
12
|
+
import type { generateCustomEventMethods } from "./CustomEventMethods";
|
|
13
13
|
import type { CustomSetData } from "./CustomSetData";
|
|
14
14
|
export type RootComponentInstance<
|
|
15
15
|
TIsPage extends boolean,
|
|
16
16
|
TMethods extends object,
|
|
17
17
|
TDataForSetData extends object,
|
|
18
18
|
AllData extends object,
|
|
19
|
-
|
|
19
|
+
CustomEventsDef extends object,
|
|
20
20
|
StoreDoc extends object,
|
|
21
21
|
instanceData = ComputeObject<Assign<IInjectAllData, ComputeIntersection<AllData>>>,
|
|
22
22
|
> =
|
|
@@ -30,7 +30,7 @@ export type RootComponentInstance<
|
|
|
30
30
|
disposer: { [k in keyof StoreDoc]: IReactionDisposer };
|
|
31
31
|
}>
|
|
32
32
|
// 自身methods覆盖注入的methods
|
|
33
|
-
& Assign<IInjectMethods, TMethods &
|
|
33
|
+
& Assign<IInjectMethods, TMethods & generateCustomEventMethods<CustomEventsDef>>
|
|
34
34
|
& { data: instanceData };
|
|
35
35
|
// & { cloneData: ComputeObject<Assign<IInjectData, ComputeIntersection<AllData>>> };
|
|
36
36
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
-
import type { ComputeObject } from "../../../types/
|
|
3
|
+
import type { ComputeObject } from "../../../types/ComputeObject";
|
|
4
4
|
import type { WMCompPageLifetimes, WMPageLifetimes } from "../../../types/OfficialTypeAlias";
|
|
5
5
|
import type { RemoveNullOfRequired } from "../../../types/RemoveNullOfRequired";
|
|
6
6
|
|
|
@@ -5,7 +5,7 @@ import type { OptionalType } from "./PropertiesConstraint";
|
|
|
5
5
|
/**
|
|
6
6
|
* 获取properties可传字段文档类型
|
|
7
7
|
*/
|
|
8
|
-
export type
|
|
8
|
+
export type GetOptionalDef<
|
|
9
9
|
TOptionalProperties extends Record<string, OptionalType>,
|
|
10
10
|
> = {
|
|
11
11
|
-readonly [k in keyof TOptionalProperties]?: IfExtends<
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Select } from "hry-types/src/Object/Select";
|
|
2
|
+
|
|
3
|
+
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
4
|
+
import type { GetOptionalDef } from "./GetOptionalDef";
|
|
5
|
+
|
|
6
|
+
import type { GetRequiredDef } from "./GetRequiredDef";
|
|
7
|
+
import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
|
|
8
|
+
|
|
9
|
+
type _GetPropertiesDef<
|
|
10
|
+
TProperties extends PropertiesConstraint,
|
|
11
|
+
OptionalDef extends object =
|
|
12
|
+
// @ts-expect-error ddd
|
|
13
|
+
GetOptionalDef<Select<TProperties, OptionalType>>,
|
|
14
|
+
RequiredDef extends object =
|
|
15
|
+
// @ts-expect-error dddf
|
|
16
|
+
GetRequiredDef<Omit<TProperties, keyof OptionalDef>>,
|
|
17
|
+
> = ComputeIntersection<OptionalDef & RequiredDef>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* properties字段的文档类型
|
|
21
|
+
* @remarks 必传的字段如果是object,要联合上null类型,选传的object根据是否是页面来决定是否加null
|
|
22
|
+
*/
|
|
23
|
+
export type GetPropertiesDef<
|
|
24
|
+
TProperties extends PropertiesConstraint,
|
|
25
|
+
> = _GetPropertiesDef<TProperties>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
2
|
+
import type { RequiredSingle, RequiredType, RequiredUnion } from "./PropertiesConstraint";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 获取properties必传字段的文档类型
|
|
6
|
+
* @remarks 小程序中必传字段如果是object,默认类型为null,所以组件文档对象类型要联合上null类型
|
|
7
|
+
*/
|
|
8
|
+
export type GetRequiredDef<
|
|
9
|
+
TProperties extends Record<string, RequiredType>,
|
|
10
|
+
> = {
|
|
11
|
+
-readonly [k in keyof TProperties]: TProperties[k] extends RequiredSingle ? InferDetailedType<TProperties[k]>
|
|
12
|
+
: TProperties[k] extends RequiredUnion ?
|
|
13
|
+
| InferDetailedType<TProperties[k]["type"]>
|
|
14
|
+
| InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
15
|
+
: never;
|
|
16
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { typeEqual } from "../../../utils/typeEqual";
|
|
2
2
|
import type { Getter } from "./StoreConstraint";
|
|
3
3
|
// 单独Getter类型返回值会把undefined转换为null
|
|
4
4
|
// 但是WithDefault类型返回值为getter的返回值去除undefined和default的类型联合。
|
|
5
|
-
export type
|
|
5
|
+
export type GetStoreDef<TStore extends object> = {
|
|
6
6
|
[k in keyof TStore]: TStore[k] extends Getter ? ReturnType<TStore[k]>
|
|
7
7
|
: TStore[k] extends {
|
|
8
8
|
getter: (...args: unknown[]) => infer R;
|
|
@@ -13,7 +13,7 @@ export type GetStoreDoc<TStore extends object> = {
|
|
|
13
13
|
|
|
14
14
|
// test
|
|
15
15
|
type User = { name: string; age: number };
|
|
16
|
-
type test =
|
|
16
|
+
type test = GetStoreDef<{
|
|
17
17
|
userName: (data: { aaa: "string" }) => string;
|
|
18
18
|
userAge: (data: { aaa: "string" }) => number;
|
|
19
19
|
userInfo: {
|
|
@@ -25,14 +25,10 @@ type test = GetStoreDoc<{
|
|
|
25
25
|
default: [];
|
|
26
26
|
};
|
|
27
27
|
}>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
userInfo: User | null;
|
|
36
|
-
list: User[];
|
|
37
|
-
}
|
|
38
|
-
>;
|
|
28
|
+
type expected = {
|
|
29
|
+
userName: string;
|
|
30
|
+
userAge: number;
|
|
31
|
+
userInfo: User | null;
|
|
32
|
+
list: User[];
|
|
33
|
+
};
|
|
34
|
+
typeEqual<test, expected>();
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
export type Getter<T extends object = object, R = unknown> = (data: T) => R;
|
|
2
|
-
|
|
3
|
-
export type WithDefault<T extends object = object, R = unknown> = {
|
|
4
|
-
getter: Getter<T, R | undefined>;
|
|
5
|
-
default: unknown;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type StoreConstraint<T extends object = object> = Record<string, Getter<T> | WithDefault<T>>;
|
|
2
|
+
export type StoreConstraint<T extends object = object> = Record<string, Getter<T>>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
2
|
import type { As } from "hry-types/src/Any/As";
|
|
3
3
|
import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
4
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
5
|
-
import type { IsPureObject } from "hry-types/src/Any/IsPureObject";
|
|
6
4
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
7
5
|
import type { Validators } from "../../../types/Validators";
|
|
8
6
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
@@ -45,43 +43,11 @@ export type StoreOption<
|
|
|
45
43
|
export type TypeValidator<
|
|
46
44
|
TStore,
|
|
47
45
|
Result = {
|
|
48
|
-
[k in keyof TStore]:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
R,
|
|
55
|
-
undefined,
|
|
56
|
-
// 如果包含undefined时
|
|
57
|
-
IfExtends<
|
|
58
|
-
// 是否为纯对象
|
|
59
|
-
IsPureObject<Exclude<R, undefined>>,
|
|
60
|
-
true,
|
|
61
|
-
// 如果是纯对象,则default可以为null
|
|
62
|
-
IfExtends<
|
|
63
|
-
D,
|
|
64
|
-
Exclude<R, undefined> | null,
|
|
65
|
-
unknown,
|
|
66
|
-
{ default: () => "⚠️类型错误⚠️" }
|
|
67
|
-
>,
|
|
68
|
-
// 如果不是纯对象,则default只能为getter返回值
|
|
69
|
-
IfExtends<
|
|
70
|
-
D,
|
|
71
|
-
Exclude<R, undefined>,
|
|
72
|
-
unknown,
|
|
73
|
-
{ default: () => "⚠️类型错误⚠️" }
|
|
74
|
-
>
|
|
75
|
-
>,
|
|
76
|
-
// 不包含undefined时,报错getter
|
|
77
|
-
{ getter: () => "⚠️类型不包含undefined⚠️ " }
|
|
78
|
-
>
|
|
79
|
-
// 非对象形式
|
|
80
|
-
: IfContains<
|
|
81
|
-
ReturnType<As<TStore[k], Func>>,
|
|
82
|
-
undefined,
|
|
83
|
-
() => "⚠️类型包含undefined,应写成对象形式⚠️",
|
|
84
|
-
unknown
|
|
85
|
-
>;
|
|
46
|
+
[k in keyof TStore]: IfContains<
|
|
47
|
+
ReturnType<As<TStore[k], Func>>,
|
|
48
|
+
undefined,
|
|
49
|
+
() => "⚠️返回类型中不可以包含undefined⚠️",
|
|
50
|
+
unknown
|
|
51
|
+
>;
|
|
86
52
|
},
|
|
87
53
|
> = Record<keyof TStore, unknown> extends Result ? unknown : Result;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { observable } from "mobx";
|
|
2
|
-
import type { DetailedType } from "../../../../types/DetailedType";
|
|
3
2
|
import { RootComponent } from "../..";
|
|
4
3
|
const user = observable({
|
|
5
4
|
name: "zhao",
|
|
@@ -29,44 +28,10 @@ RootComponent()({
|
|
|
29
28
|
userAge: () => user.age,
|
|
30
29
|
},
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
name: string;
|
|
34
|
-
age?: number;
|
|
35
|
-
};
|
|
36
|
-
type AllGoods = Record<string, User[] | undefined>;
|
|
37
|
-
const M_User = observable({
|
|
38
|
-
allUser: {
|
|
39
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
40
|
-
categoryB: [{ name: "zhao" }],
|
|
41
|
-
} as AllGoods,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// store中getter函数第一个参数为properties的类型
|
|
31
|
+
// 3. 返回类型错误
|
|
45
32
|
RootComponent()({
|
|
46
|
-
properties: {
|
|
47
|
-
categoryId: String as DetailedType<keyof typeof M_User.allUser>,
|
|
48
|
-
},
|
|
49
|
-
data: {
|
|
50
|
-
// categoryList:[],
|
|
51
|
-
},
|
|
52
33
|
store: {
|
|
53
|
-
// @ts-expect-error 1
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_categoryList: {
|
|
57
|
-
// @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
|
|
58
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[],
|
|
59
|
-
default: [],
|
|
60
|
-
},
|
|
61
|
-
_categoryList1: {
|
|
62
|
-
getter: (data) => M_User.allUser[data.categoryId],
|
|
63
|
-
// @ts-expect-error 3 默认值应该为[]
|
|
64
|
-
default: 0,
|
|
65
|
-
},
|
|
66
|
-
_categoryList2: {
|
|
67
|
-
getter: (data) => M_User.allUser[data.categoryId]?.[0],
|
|
68
|
-
// @ts-expect-error 3 默认值应该为null
|
|
69
|
-
default: 0,
|
|
70
|
-
},
|
|
34
|
+
// @ts-expect-error 3.1 返回类型中不可以包含undefined
|
|
35
|
+
xxx: () => "xxx" as string | undefined,
|
|
71
36
|
},
|
|
72
37
|
});
|