annil 1.13.0 → 1.13.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 +16 -0
- package/dist/api/ChunkComponent/index.d.ts +3 -3
- package/dist/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.d.ts +1 -1
- package/dist/api/CustomComponent/index.d.ts +2 -2
- package/dist/api/CustomComponent/returnType.d.ts +1 -2
- 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/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/types/ComputeObject.js +2 -0
- package/dist/types/ComputeObject.js.map +1 -0
- package/dist/utils/typeEqual.d.ts +2 -1
- package/dist/utils/typeEqual.js +1 -1
- 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/index.ts +4 -4
- package/src/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.ts +1 -1
- package/src/api/CustomComponent/index.ts +2 -2
- package/src/api/CustomComponent/returnType.ts +1 -14
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +4 -4
- package/src/api/DefineComponent/index.ts +4 -4
- 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/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/index.ts +50 -50
- package/src/api/wxSugar.ts +1 -1
- package/src/index.ts +1 -2
- package/src/thirdLib/wm/swiper.test.ts +4 -6
- package/src/utils/typeEqual.ts +22 -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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { typeEqual } from "../../../../utils/typeEqual";
|
|
2
2
|
import type { CustomComponentDefinition } from "../../../CustomComponent/returnType";
|
|
3
3
|
import type { Bubbles, Composed } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
4
4
|
import { DefineComponent } from "../..";
|
|
@@ -1039,11 +1039,11 @@ const aaa = DefineComponent({
|
|
|
1039
1039
|
A,
|
|
1040
1040
|
],
|
|
1041
1041
|
});
|
|
1042
|
-
|
|
1043
|
-
void Checking<typeof aaa, {
|
|
1042
|
+
type Epected = {
|
|
1044
1043
|
events: {
|
|
1045
1044
|
test_a: string | number | boolean | Composed;
|
|
1046
1045
|
test_b: string | number | Composed;
|
|
1047
1046
|
test_c: boolean | Composed;
|
|
1048
1047
|
};
|
|
1049
|
-
}
|
|
1048
|
+
};
|
|
1049
|
+
typeEqual<Epected>()(aaa);
|
|
@@ -27,7 +27,7 @@ type Constructor = <
|
|
|
27
27
|
TPath extends Path = "/",
|
|
28
28
|
>(
|
|
29
29
|
options: Options<TRootComponentDefinition, TCustomComponentDefinitionList, TName, TPath>,
|
|
30
|
-
) => // 根据是否传入name
|
|
30
|
+
) => // 根据是否传入name字段(当isPage不为true时,类型约束name不为空字符串)来区分生成页面文档还是组件文档。
|
|
31
31
|
IfExtends<
|
|
32
32
|
"",
|
|
33
33
|
TName,
|
|
@@ -45,14 +45,14 @@ export type DefineComponentOptionRuntime = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* DefineComponent是构建组件的核心API
|
|
49
|
-
* 它返回的类型可能是页面文档(`PageDoc`)或者自定义组件文档(`ComponentDoc`)
|
|
48
|
+
* DefineComponent是构建组件的核心API,所有组件(页面组件和自定义组件)都通过它来构建的。
|
|
49
|
+
* 它返回的类型可能是页面文档(`PageDoc`)或者自定义组件文档(`ComponentDoc`),具体取决于传入rootComponent中isPage的值。
|
|
50
50
|
* 它的作用是把根组件定义(`RootComponentDefinition`)和子组件定义(`CustomComponentDefinition`和`ChunkComponentDefinition`)整合成原生`Component`的选项配置,最终通过原生`Component`来构建组件。
|
|
51
51
|
*/
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- 返回类型由Constructor定义,实现无需。
|
|
53
53
|
export const DefineComponent: Constructor = function(options): any {
|
|
54
54
|
Component(
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Options泛型中properties字段类型与WechatMiniprogram.Component.Constructor中的properties字段类型不兼容,但运行时是兼容的,所以这里使用any
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Options泛型中properties字段类型与WechatMiniprogram.Component.Constructor中的properties字段类型不兼容,但运行时是兼容的,所以这里使用any。
|
|
56
56
|
normalizeOptions(options as DefineComponentOptionRuntime) as any,
|
|
57
57
|
);
|
|
58
58
|
};
|
|
@@ -5,10 +5,9 @@ import type { ComputedConstraint } from "./ComputedConstraint";
|
|
|
5
5
|
export type ComputedOption<
|
|
6
6
|
TComputed extends ComputedConstraint,
|
|
7
7
|
CompareKeys extends PropertyKey,
|
|
8
|
-
>
|
|
9
|
-
= {
|
|
8
|
+
> = {
|
|
10
9
|
/**
|
|
11
|
-
* computed
|
|
10
|
+
* computed字段
|
|
12
11
|
* @remarks
|
|
13
12
|
*
|
|
14
13
|
* 函数体内,可通过this.data获取实例其他数据(依赖),setData发生时,若数据(依赖)发生变化则重新运行函数体并setData。
|
|
@@ -5,6 +5,6 @@ import type { ComputedConstraint } from "./ComputedConstraint";
|
|
|
5
5
|
* @param T - ComputedConstraint
|
|
6
6
|
* @returns object
|
|
7
7
|
*/
|
|
8
|
-
export type
|
|
8
|
+
export type GetComputedDef<TComputed extends ComputedConstraint> = {
|
|
9
9
|
[k in keyof TComputed]: ReturnType<TComputed[k]>;
|
|
10
10
|
};
|
|
@@ -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
|
>;
|
|
@@ -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>();
|