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
|
@@ -22,49 +22,3 @@ interface StoreDocExpected {
|
|
|
22
22
|
|
|
23
23
|
// 返回类型为函数返回类型
|
|
24
24
|
void Checking<typeof storeDoc, StoreDocExpected, Test.Pass>;
|
|
25
|
-
|
|
26
|
-
type User = {
|
|
27
|
-
name: string;
|
|
28
|
-
age?: number;
|
|
29
|
-
};
|
|
30
|
-
type AllGoods = Record<string, User[]>;
|
|
31
|
-
const M_User = observable({
|
|
32
|
-
allUser: {
|
|
33
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
34
|
-
categoryB: [{ name: "zhao" }],
|
|
35
|
-
} as AllGoods,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// store中getter函数第一个参数为properties的类型
|
|
39
|
-
RootComponent()({
|
|
40
|
-
properties: {
|
|
41
|
-
categoryId: String,
|
|
42
|
-
},
|
|
43
|
-
data: {
|
|
44
|
-
// categoryList:[],
|
|
45
|
-
},
|
|
46
|
-
store: {
|
|
47
|
-
// 1 响应式不包含undefined时 只能写成getter函数形式
|
|
48
|
-
categoryList: (data) => M_User.allUser[data.categoryId],
|
|
49
|
-
// 2 响应式数据包含undefined时 只能写成对象形式
|
|
50
|
-
_categoryList: {
|
|
51
|
-
getter: (data) => M_User.allUser[data.categoryId][0].age,
|
|
52
|
-
default: 0,
|
|
53
|
-
},
|
|
54
|
-
_categoryList1: {
|
|
55
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
|
|
56
|
-
// 默认值为[]
|
|
57
|
-
default: [],
|
|
58
|
-
},
|
|
59
|
-
_categoryList2: {
|
|
60
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
61
|
-
// 对象类型 默认值为User类型
|
|
62
|
-
default: { name: "zhao", age: 20 },
|
|
63
|
-
},
|
|
64
|
-
_categoryList3: {
|
|
65
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
66
|
-
// 对象类型 默认值可以为null
|
|
67
|
-
default: null,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});
|
|
@@ -2,17 +2,17 @@ import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
|
2
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
3
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
4
4
|
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
5
|
-
import type { ComputeObject } from "../../types/
|
|
5
|
+
import type { ComputeObject } from "../../types/ComputeObject";
|
|
6
6
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
7
7
|
import type { RemoveNullOfRequired } from "../../types/RemoveNullOfRequired";
|
|
8
8
|
import type { ComponentDoc } from "../DefineComponent/returnType/ComponentDoc";
|
|
9
9
|
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
10
10
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
11
11
|
import type { ComputedOption } from "./Computed/ComputedOption";
|
|
12
|
-
import type {
|
|
12
|
+
import type { GetComputedDef } from "./Computed/GetComputedDef";
|
|
13
13
|
import type { CustomEventConstraint } from "./CustomEvents/CustomEventConstraint";
|
|
14
14
|
import type { CustomEventsOption } from "./CustomEvents/CustomEventsOption";
|
|
15
|
-
import type {
|
|
15
|
+
import type { GetCustomEventsDef } from "./CustomEvents/GetCustomEventDef";
|
|
16
16
|
import type { DataOption } from "./Data/DataOption";
|
|
17
17
|
import type { EventsConstraint } from "./Events/EventsConstraint";
|
|
18
18
|
import type { EventsOption } from "./Events/EventsOption";
|
|
@@ -23,10 +23,10 @@ import type { MethodsConstraint } from "./Methods/MethodsConstraint";
|
|
|
23
23
|
import type { MethodsOption } from "./Methods/MethodsOption";
|
|
24
24
|
import type { ObserversOption } from "./Observers/ObserversOption";
|
|
25
25
|
import type { PageLifetimesOption } from "./PageLifetimes/PageLifetimesOption";
|
|
26
|
-
import type {
|
|
26
|
+
import type { GetPropertiesDef } from "./Properties/GetPropertiesDef";
|
|
27
27
|
import type { PropertiesConstraint } from "./Properties/PropertiesConstraint";
|
|
28
28
|
import type { PropertiesOption } from "./Properties/PropertiesOption";
|
|
29
|
-
import type {
|
|
29
|
+
import type { GetStoreDef } from "./Store/GetStoreDef";
|
|
30
30
|
import type { StoreConstraint } from "./Store/StoreConstraint";
|
|
31
31
|
import type { StoreOption } from "./Store/StoreOption";
|
|
32
32
|
import type { WatchOption } from "./Watch/WatchOption";
|
|
@@ -40,55 +40,55 @@ type RootComponentOptions<
|
|
|
40
40
|
TData extends object,
|
|
41
41
|
TStore extends StoreConstraint,
|
|
42
42
|
TComputed extends Record<string, Func>,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
EventsDef extends object,
|
|
44
|
+
CustomEventsDef extends object,
|
|
45
|
+
PropertiesDef extends object,
|
|
46
|
+
DataDef extends object,
|
|
47
|
+
StoreDef extends object,
|
|
48
|
+
ComputedDef extends object,
|
|
49
49
|
> =
|
|
50
|
-
& MethodsOption<TMethods, keyof (
|
|
50
|
+
& MethodsOption<TMethods, keyof (EventsDef & CustomEventsDef)>
|
|
51
51
|
& PropertiesOption<TProperties>
|
|
52
52
|
& IsPageOption<TIsPage>
|
|
53
53
|
& EventsOption<TEvents>
|
|
54
|
-
& CustomEventsOption<TCustomEvents, keyof
|
|
55
|
-
& DataOption<TData, keyof
|
|
56
|
-
& StoreOption<TStore, keyof (
|
|
54
|
+
& IfExtends<TIsPage, false, CustomEventsOption<TCustomEvents, keyof EventsDef>, {}>
|
|
55
|
+
& DataOption<TData, keyof PropertiesDef>
|
|
56
|
+
& StoreOption<TStore, keyof (PropertiesDef & DataDef)>
|
|
57
57
|
& ComputedOption<
|
|
58
58
|
TComputed,
|
|
59
|
-
keyof (
|
|
60
|
-
> // { data: ComputeObject<
|
|
61
|
-
& PageLifetimesOption<TIsPage,
|
|
59
|
+
keyof (PropertiesDef & DataDef & StoreDef)
|
|
60
|
+
> // { data: ComputeObject<DataDef & Required<PropertiesDef> & StoreDef & ComputedDef & IInjectAllData> }
|
|
61
|
+
& PageLifetimesOption<TIsPage, PropertiesDef>
|
|
62
62
|
& LifetimesOption
|
|
63
63
|
& WatchOption<
|
|
64
|
-
&
|
|
65
|
-
& Required<
|
|
66
|
-
&
|
|
67
|
-
&
|
|
64
|
+
& ComputedDef
|
|
65
|
+
& Required<PropertiesDef>
|
|
66
|
+
& DataDef
|
|
67
|
+
& StoreDef
|
|
68
68
|
& IInjectStore
|
|
69
69
|
>
|
|
70
70
|
& Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "observers">>
|
|
71
71
|
& ObserversOption<
|
|
72
|
-
&
|
|
73
|
-
& Required<
|
|
74
|
-
&
|
|
75
|
-
&
|
|
72
|
+
& ComputedDef
|
|
73
|
+
& Required<PropertiesDef>
|
|
74
|
+
& DataDef
|
|
75
|
+
& StoreDef
|
|
76
76
|
& IInjectStore
|
|
77
77
|
>
|
|
78
78
|
& ThisType<
|
|
79
79
|
RootComponentInstance<
|
|
80
80
|
TIsPage,
|
|
81
81
|
TMethods,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
DataDef,
|
|
83
|
+
DataDef & Required<PropertiesDef> & StoreDef & ComputedDef,
|
|
84
|
+
CustomEventsDef,
|
|
85
|
+
StoreDef
|
|
86
86
|
>
|
|
87
87
|
>;
|
|
88
88
|
|
|
89
89
|
type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = <
|
|
90
90
|
TEvents extends EventsConstraint<TComponentDocList>,
|
|
91
|
-
TStore extends StoreConstraint<
|
|
91
|
+
TStore extends StoreConstraint<PropertiesDef>,
|
|
92
92
|
TIsPage extends boolean = false,
|
|
93
93
|
const TProperties extends PropertiesConstraint = {},
|
|
94
94
|
TData extends object = {},
|
|
@@ -96,12 +96,12 @@ type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = <
|
|
|
96
96
|
// 页面时自定义事件无意义
|
|
97
97
|
TCustomEvents extends IfExtends<TIsPage, false, CustomEventConstraint, EmptyObject> = {},
|
|
98
98
|
TMethods extends MethodsConstraint = {},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
EventsDef extends object = IfExtends<EventsConstraint<TComponentDocList>, TEvents, {}, TEvents>,
|
|
100
|
+
CustomEventsDef extends object = GetCustomEventsDef<TCustomEvents>,
|
|
101
|
+
PropertiesDef extends object = GetPropertiesDef<TProperties>,
|
|
102
|
+
DataDef extends object = TData,
|
|
103
|
+
StoreDef extends object = StoreConstraint<PropertiesDef> extends TStore ? {} : GetStoreDef<TStore>,
|
|
104
|
+
ComputedDef extends object = GetComputedDef<TComputed>,
|
|
105
105
|
>(
|
|
106
106
|
options: RootComponentOptions<
|
|
107
107
|
TEvents,
|
|
@@ -113,28 +113,28 @@ type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = <
|
|
|
113
113
|
TStore,
|
|
114
114
|
TComputed,
|
|
115
115
|
// TObservers,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
EventsDef,
|
|
117
|
+
CustomEventsDef,
|
|
118
|
+
PropertiesDef,
|
|
119
|
+
DataDef,
|
|
120
|
+
StoreDef,
|
|
121
|
+
ComputedDef
|
|
122
122
|
>,
|
|
123
123
|
) => // 生成RootComponentDefinition
|
|
124
124
|
ComputeIntersection<
|
|
125
125
|
& IfExtends<TIsPage, false, {}, { isPage: true }>
|
|
126
126
|
& IfExtends<
|
|
127
127
|
EmptyObject,
|
|
128
|
-
|
|
128
|
+
PropertiesDef,
|
|
129
129
|
{},
|
|
130
|
-
{ properties: IfExtends<false, TIsPage,
|
|
130
|
+
{ properties: IfExtends<false, TIsPage, PropertiesDef, RemoveNullOfRequired<PropertiesDef>> }
|
|
131
131
|
>
|
|
132
|
-
& IfExtends<EmptyObject,
|
|
133
|
-
& IfExtends<EmptyObject,
|
|
134
|
-
& IfExtends<EmptyObject,
|
|
132
|
+
& IfExtends<EmptyObject, DataDef, {}, { data: DataDef }>
|
|
133
|
+
& IfExtends<EmptyObject, StoreDef, {}, { store: ComputeObject<StoreDef> }>
|
|
134
|
+
& IfExtends<EmptyObject, ComputedDef, {}, { computed: ComputedDef }>
|
|
135
135
|
& IfExtends<EmptyObject, TMethods, {}, { methods: TMethods }>
|
|
136
|
-
& IfExtends<EmptyObject,
|
|
137
|
-
& IfExtends<EmptyObject,
|
|
136
|
+
& IfExtends<EmptyObject, EventsDef, {}, { events: EventsDef }>
|
|
137
|
+
& IfExtends<EmptyObject, CustomEventsDef, {}, { customEvents: ComputeObject<CustomEventsDef> }>
|
|
138
138
|
>;
|
|
139
139
|
/**
|
|
140
140
|
* RootComponent API
|
package/src/api/wxSugar.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfEquals } from "hry-types/src/Any/IfEquals";
|
|
2
2
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
3
3
|
import type { NoInfer } from "hry-types/src/Generic/NoInfer";
|
|
4
|
-
import type { ComputeObject } from "../types/
|
|
4
|
+
import type { ComputeObject } from "../types/ComputeObject";
|
|
5
5
|
import type { WMNavigateToOption } from "../types/OfficialTypeAlias";
|
|
6
6
|
import type { RequiredKeys } from "../types/RequiredKeys";
|
|
7
7
|
import { INNERMARKER } from "../utils/InnerMarker";
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { navigateBack, navigateTo, redirectTo } from "./api/wxSugar";
|
|
|
7
7
|
import type { CreateComponentType } from "./types/CreateComponentType";
|
|
8
8
|
import type { DetailedType } from "./types/DetailedType";
|
|
9
9
|
import type { ExtendComponentType } from "./types/ExtendComponentType";
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
export * from "./utils/_utils";
|
|
12
12
|
|
|
13
13
|
export type {
|
|
@@ -43,7 +43,6 @@ export {
|
|
|
43
43
|
instanceConfig,
|
|
44
44
|
navigateBack,
|
|
45
45
|
navigateTo,
|
|
46
|
-
type ParamsEqual,
|
|
47
46
|
redirectTo,
|
|
48
47
|
RootComponent,
|
|
49
48
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CustomComponent, typeEqual } from "../../index";
|
|
2
|
+
import type { Wm } from "../index";
|
|
3
|
+
|
|
4
|
+
CustomComponent<{}, Wm.Swiper>()({
|
|
5
|
+
data: {
|
|
6
|
+
swiper_style: "16/9",
|
|
7
|
+
},
|
|
8
|
+
computed: {
|
|
9
|
+
swiper_class() {
|
|
10
|
+
return `w-full h-auto ${this.data.swiper_style}`;
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
events: {
|
|
14
|
+
swiper_change(e) {
|
|
15
|
+
typeEqual<number>(e.detail.current);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
swiper_animationfinish(e) {
|
|
19
|
+
typeEqual<number>(e.detail.current);
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -94,7 +94,7 @@ export type Swiper = CreateComponentType<"swiper", {
|
|
|
94
94
|
*/
|
|
95
95
|
easingFunction?: "defaultValue" | "linear" | "easeInCubic" | "easeOutCubic" | "easeInOutCubic";
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
events: {
|
|
98
98
|
/**
|
|
99
99
|
* current 改变时会触发 change 事件,event.detail = `{current, source}`
|
|
100
100
|
*/
|
|
@@ -11,7 +11,7 @@ import type { AddPrefix } from "./AddPrefix";
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* type $CustomA = CreateComponentType<"customA", {
|
|
13
13
|
* properties: { num: string };
|
|
14
|
-
*
|
|
14
|
+
* events: { onTap: string }
|
|
15
15
|
* }>;
|
|
16
16
|
*
|
|
17
17
|
* // 等同下面的类型
|
|
@@ -19,7 +19,7 @@ import type { AddPrefix } from "./AddPrefix";
|
|
|
19
19
|
* properties: {
|
|
20
20
|
* customA_num: string;
|
|
21
21
|
* };
|
|
22
|
-
*
|
|
22
|
+
* events: {
|
|
23
23
|
* customA_onTap: string;
|
|
24
24
|
* };
|
|
25
25
|
* ```
|
|
@@ -27,10 +27,10 @@ type Validator<
|
|
|
27
27
|
* ```ts
|
|
28
28
|
* type $CustomA = ExtendComponentType<
|
|
29
29
|
* { properties: { aaa_num: number };
|
|
30
|
-
*
|
|
30
|
+
* events: { aaa_xxx: string }
|
|
31
31
|
* },
|
|
32
32
|
* { properties: { aaa_str: string };
|
|
33
|
-
*
|
|
33
|
+
* events: { aaa_yyy: string }
|
|
34
34
|
* }>;
|
|
35
35
|
*
|
|
36
36
|
* // 等同下面的类型
|
|
@@ -39,7 +39,7 @@ type Validator<
|
|
|
39
39
|
* aaa_num: number;
|
|
40
40
|
* aaa_str: string;
|
|
41
41
|
* };
|
|
42
|
-
*
|
|
42
|
+
* events: {
|
|
43
43
|
* aaa_xxx: string;
|
|
44
44
|
* aaa_yyy: string;
|
|
45
45
|
* };
|
|
@@ -53,8 +53,8 @@ export type ExtendComponentType<
|
|
|
53
53
|
|
|
54
54
|
// type test0 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
55
55
|
|
|
56
|
-
// type test1 = ExtendComponentType<{
|
|
56
|
+
// type test1 = ExtendComponentType<{ events: { aaa_xxx: string } }, { events: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
57
57
|
|
|
58
58
|
// type test2 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
59
59
|
|
|
60
|
-
// type test3 = ExtendComponentType<{
|
|
60
|
+
// type test3 = ExtendComponentType<{ events: { aaa_xxx: string } }, { events: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
package/src/utils/nonNullable.ts
CHANGED
|
@@ -2,15 +2,18 @@ import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 使用此函数代替!断言
|
|
5
|
+
* 支持可选的第二个参数作为错误消息
|
|
5
6
|
* @param value 类型中必须包含 null 或 undefined
|
|
7
|
+
* @param message 可选,抛出错误时的消息
|
|
6
8
|
* @returns 去除 null 和 undefined 后的类型
|
|
7
9
|
*/
|
|
8
10
|
export function nonNullable<T>(
|
|
9
11
|
value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined">,
|
|
12
|
+
message?: string,
|
|
10
13
|
): NonNullable<T> {
|
|
11
14
|
/* istanbul ignore next */
|
|
12
15
|
if (value === null || value === undefined) {
|
|
13
|
-
throw new Error(`${value} should not be null or undefined`);
|
|
16
|
+
throw new Error(message ?? `${value} should not be null or undefined`);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
return value as NonNullable<T>;
|
package/src/utils/typeEqual.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { Equals } from "hry-types/src/Any/Equals";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* 类型相等验证
|
|
5
4
|
* @example
|
|
6
5
|
* ```ts
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* const a = 1;
|
|
7
|
+
* type A = typeof a;
|
|
8
|
+
* const b = 2;
|
|
9
|
+
* type B = typeof b;
|
|
10
|
+
* typeEqual<A, B>(); // B位置报错
|
|
11
|
+
* typeEqual<A>(a); // 不报错
|
|
9
12
|
* ```
|
|
10
13
|
*/
|
|
11
14
|
export function typeEqual<
|
|
12
|
-
A,
|
|
13
|
-
B extends Equals<A, B> extends true ? unknown : never,
|
|
14
|
-
>() {
|
|
15
|
-
void
|
|
15
|
+
const A,
|
|
16
|
+
const B extends Equals<A, B> extends true ? unknown : never = never,
|
|
17
|
+
>(a?: NoInfer<A>): void {
|
|
18
|
+
void a;
|
|
16
19
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Equals } from "hry-types/src/Any/Equals";
|
|
2
|
+
export type InqualityCall<A> = <const B>(b: B, ...nullable: Equals<A, B> extends false ? [] : [never]) => void;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 类型和变量不等验证
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const a = { a: 1 } as const;
|
|
9
|
+
* type B = { a: number };
|
|
10
|
+
* typeNotEqual<B>()(a); 不报错
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function typeNotEqual<
|
|
14
|
+
const A,
|
|
15
|
+
>(): InqualityCall<A>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 二个类型不等验证
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const a = 1;
|
|
22
|
+
* type A = typeof a;
|
|
23
|
+
* const b = 2;
|
|
24
|
+
* type B = typeof b;
|
|
25
|
+
* typeNotEqual<A, B>(); 不报错
|
|
26
|
+
*/
|
|
27
|
+
export function typeNotEqual<
|
|
28
|
+
const A,
|
|
29
|
+
const B extends Equals<A, B> extends false ? unknown : never = never,
|
|
30
|
+
>(): void;
|
|
31
|
+
/**
|
|
32
|
+
* 类型不等验证
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const a = 1;
|
|
36
|
+
* type A = typeof a;
|
|
37
|
+
* const b = 2;
|
|
38
|
+
* type B = typeof b;
|
|
39
|
+
* typeNotEqual<A, B>(); // 不报错
|
|
40
|
+
* typeNotEqual<A>()(b); // 不报错
|
|
41
|
+
* typeNotEqual<A>()(a); // 报错
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function typeNotEqual<
|
|
45
|
+
const A,
|
|
46
|
+
>(): void | InqualityCall<A> {
|
|
47
|
+
void 0;
|
|
48
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetComputedDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/Computed/GetComputedDoc.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
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 { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents, SimpleCustomeEventsList } from "./CustomEventConstraint";
|
|
5
|
-
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
6
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T> : T extends null ? null : T extends undefined ? undefined : T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]> : never;
|
|
7
|
-
export type GetFullCustomEventsDoc<T extends FullCustomEvents> = GetShortCustomEventsDoc<T["detail"]> | IfExtends<unknown, T["options"], never, AddTagForCustomEventsDoc<T["options"] & {}>>;
|
|
8
|
-
export type GetCustomEventDoc<T extends CustomEventConstraint> = {
|
|
9
|
-
[k in keyof T]: T[k] extends ShortCustomeEvents ? GetShortCustomEventsDoc<T[k]> : GetShortCustomEventsDoc<T[k]["detail"]> | IfExtends<unknown, T[k]["options"], never, AddTagForCustomEventsDoc<T[k]["options"] & {}>>;
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetCustomEventDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetOptionalDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/Properties/GetOptionalDoc.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Select } from "hry-types/src/Object/Select";
|
|
2
|
-
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
3
|
-
import type { GetOptionalDoc } from "./GetOptionalDoc";
|
|
4
|
-
import type { GetRequiredDoc } from "./GetRequiredDoc";
|
|
5
|
-
import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
|
|
6
|
-
type _GetPropertiesDoc<TProperties extends PropertiesConstraint, OptionalDoc extends object = GetOptionalDoc<Select<TProperties, OptionalType>>, RequiredDoc extends object = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>>> = ComputeIntersection<OptionalDoc & RequiredDoc>;
|
|
7
|
-
export type GetPropertiesDoc<TProperties extends PropertiesConstraint> = _GetPropertiesDoc<TProperties>;
|
|
8
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetPropertiesDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/Properties/GetPropertiesDoc.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
|
-
import type { RequiredSingle, RequiredType } from "./PropertiesConstraint";
|
|
4
|
-
export type GetRequiredDoc<TProperties extends Record<string, RequiredType>> = {
|
|
5
|
-
-readonly [k in keyof TProperties]: IfExtends<TProperties[k], RequiredSingle, InferDetailedType<TProperties[k]>, InferDetailedType<TProperties[k]["type"]> | InferDetailedType<TProperties[k]["optionalTypes"][number]>>;
|
|
6
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GetRequiredDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/Properties/GetRequiredDoc.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeTStoreDoc.js","sourceRoot":"","sources":["../../../../src/api/RootComponent/Store/GeTStoreDoc.ts"],"names":[],"mappings":""}
|
package/dist/types/ComputeObj.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ComputeObj.js","sourceRoot":"","sources":["../../src/types/ComputeObj.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TwoParamsEqual.js","sourceRoot":"","sources":["../../src/types/TwoParamsEqual.ts"],"names":[],"mappings":""}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Select } from "hry-types/src/Object/Select";
|
|
2
|
-
|
|
3
|
-
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
4
|
-
import type { GetOptionalDoc } from "./GetOptionalDoc";
|
|
5
|
-
import type { GetRequiredDoc } from "./GetRequiredDoc";
|
|
6
|
-
import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
|
|
7
|
-
|
|
8
|
-
type _GetPropertiesDoc<
|
|
9
|
-
TProperties extends PropertiesConstraint,
|
|
10
|
-
// TIsPage extends boolean,
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
OptionalDoc extends object = GetOptionalDoc<Select<TProperties, OptionalType>>,
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
RequiredDoc extends object = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>>,
|
|
15
|
-
> = ComputeIntersection<OptionalDoc & RequiredDoc>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* properties字段的文档类型
|
|
19
|
-
* @remarks 必传的字段如果是object,要联合上null类型,选传的object根据是否是页面来决定是否加null
|
|
20
|
-
*/
|
|
21
|
-
export type GetPropertiesDoc<
|
|
22
|
-
TProperties extends PropertiesConstraint,
|
|
23
|
-
> // TisPage extends boolean,
|
|
24
|
-
= _GetPropertiesDoc<TProperties>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
|
-
import type { RequiredSingle, RequiredType } from "./PropertiesConstraint";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 获取properties必传字段的文档类型
|
|
7
|
-
* @remarks 小程序中必传字段如果是object,默认类型为null,所以组件文档对象类型要联合上null类型
|
|
8
|
-
*/
|
|
9
|
-
export type GetRequiredDoc<
|
|
10
|
-
TProperties extends Record<string, RequiredType>,
|
|
11
|
-
> // TIsPage extends boolean,
|
|
12
|
-
= {
|
|
13
|
-
-readonly [k in keyof TProperties]: IfExtends<
|
|
14
|
-
TProperties[k],
|
|
15
|
-
// 非对象写法
|
|
16
|
-
RequiredSingle,
|
|
17
|
-
InferDetailedType<TProperties[k]>,
|
|
18
|
-
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
19
|
-
| InferDetailedType<TProperties[k]["type"]>
|
|
20
|
-
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
21
|
-
| InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
22
|
-
>;
|
|
23
|
-
};
|
|
File without changes
|
|
File without changes
|