annil 1.0.7 → 1.1.0
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 +14 -0
- package/LICENSE +1 -1
- package/dist/api/DefineComponent/NameOrPage/NameOrPathOption.d.ts +3 -3
- package/dist/api/DefineComponent/NameOrPage/test/error.test.js +4 -0
- package/dist/api/DefineComponent/NameOrPage/test/error.test.js.map +1 -1
- package/dist/api/DefineComponent/ReturnType/CreateComponentDoc.d.ts +2 -2
- package/dist/api/DefineComponent/ReturnType/CreatePageDoc.d.ts +2 -2
- package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
- package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js +1 -1
- package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
- package/dist/api/DefineComponent/SubComponents/test/normal.test.js.map +1 -1
- package/dist/api/DefineComponent/index.d.ts +1 -1
- package/dist/api/RootComponent/Properties/GetOptionalDoc.d.ts +3 -4
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +3 -4
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +3 -4
- package/dist/api/RootComponent/Store/test/normal.test.js +3 -1
- package/dist/api/RootComponent/Store/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/index.d.ts +5 -4
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/index.d.ts +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js.map +1 -1
- package/dist/types/ComponentDocExtension.d.ts +7 -0
- package/dist/types/ComponentDocExtension.js +2 -0
- package/dist/types/ComponentDocExtension.js.map +1 -0
- package/dist/types/ComputeObj.d.ts +3 -0
- package/dist/types/ComputeObj.js +2 -0
- package/dist/types/ComputeObj.js.map +1 -0
- package/dist/types/GetComponentPrefix.d.ts +2 -1
- package/dist/types/includes.d.ts +1 -0
- package/dist/types/includes.js +2 -0
- package/dist/types/includes.js.map +1 -0
- package/package.json +11 -7
- package/src/api/DefineComponent/NameOrPage/NameOrPathOption.ts +13 -8
- package/src/api/DefineComponent/NameOrPage/test/error.test.ts +10 -4
- package/src/api/DefineComponent/NameOrPage/test/normal.test.ts +2 -2
- package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +2 -2
- package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +19 -47
- package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +3 -3
- package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +3 -0
- package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +6 -12
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -4
- package/src/api/DefineComponent/index.ts +1 -1
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +0 -2
- package/src/api/RootComponent/Properties/GetOptionalDoc.ts +10 -11
- package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +6 -16
- package/src/api/RootComponent/Properties/GetRequiredDoc.ts +25 -15
- package/src/api/RootComponent/Store/test/normal.test.ts +11 -1
- package/src/api/RootComponent/index.ts +6 -5
- package/src/api/SubComponent/SubData/test/normal.test.ts +5 -2
- package/src/api/SubComponent/index.ts +2 -2
- package/src/index.ts +5 -4
- package/src/types/ComponentDocExtension.ts +36 -0
- package/src/types/ComputeObj.ts +1 -0
- package/src/types/GetComponentPrefix.ts +15 -13
- package/src/types/includes.ts +3 -0
- package/dist/api/DefineComponent/SubComponents/test/error.test.d.ts +0 -0
- package/dist/api/DefineComponent/SubComponents/test/error.test.js +0 -2
- package/dist/api/DefineComponent/SubComponents/test/error.test.js.map +0 -1
- package/dist/types/CompDocExtends.d.ts +0 -8
- package/dist/types/CompDocExtends.js +0 -2
- package/dist/types/CompDocExtends.js.map +0 -1
- package/dist/types/Drop.d.ts +0 -2
- package/dist/types/Drop.js +0 -2
- package/dist/types/Drop.js.map +0 -1
- package/dist/types/DropStr.d.ts +0 -1
- package/dist/types/DropStr.js +0 -2
- package/dist/types/DropStr.js.map +0 -1
- package/dist/types/RestorePropertiesDoc.d.ts +0 -0
- package/dist/types/RestorePropertiesDoc.js +0 -2
- package/dist/types/RestorePropertiesDoc.js.map +0 -1
- package/src/api/DefineComponent/SubComponents/test/error.test.ts +0 -14
- package/src/types/CompDocExtends.ts +0 -14
- package/src/types/Drop.ts +0 -18
- package/src/types/DropStr.ts +0 -5
- package/src/types/RestorePropertiesDoc.ts +0 -26
- package/tsconfig.json +0 -29
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import { type ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
|
|
3
2
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
4
3
|
import type { CustomEventConstraint } from "../../../RootComponent/CustomEvents/CustomEventConstraint";
|
|
5
4
|
import type {
|
|
@@ -12,6 +11,7 @@ import type {
|
|
|
12
11
|
Composed,
|
|
13
12
|
} from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
14
13
|
|
|
14
|
+
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
15
15
|
import type { PropertiesConstraint } from "../../../RootComponent/Properties/PropertiesConstraint";
|
|
16
16
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
17
17
|
import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
|
|
@@ -60,7 +60,7 @@ const customEvents = {
|
|
|
60
60
|
options: { bubbles: true, capturePhase: true, composed: true },
|
|
61
61
|
},
|
|
62
62
|
} satisfies CustomEventConstraint;
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
const OnlyPropsRootDoc = RootComponent()({
|
|
65
65
|
properties,
|
|
66
66
|
});
|
|
@@ -70,10 +70,10 @@ const onlyProperties = DefineComponent({
|
|
|
70
70
|
rootComponent: OnlyPropsRootDoc,
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
//
|
|
73
|
+
// 1. 类型为typeof OnlyPropsRootDoc加前缀(组件名)
|
|
74
74
|
type OnlyPropertiesExpected = {
|
|
75
75
|
properties: {
|
|
76
|
-
test_optionalObj?: Mock_User | null;
|
|
76
|
+
test_optionalObj?: Mock_User | null;
|
|
77
77
|
test_optionalObjOrNull?: Mock_User | null;
|
|
78
78
|
test_str: string;
|
|
79
79
|
test_obj: Mock_User | null;
|
|
@@ -82,7 +82,6 @@ type OnlyPropertiesExpected = {
|
|
|
82
82
|
|
|
83
83
|
Checking<typeof onlyProperties, OnlyPropertiesExpected, Test.Pass>;
|
|
84
84
|
|
|
85
|
-
// 只有customEvents字段
|
|
86
85
|
const OnlyCustomEventsRootDoc = RootComponent()({
|
|
87
86
|
customEvents,
|
|
88
87
|
});
|
|
@@ -92,6 +91,7 @@ const compOnlyCustomEvents = DefineComponent({
|
|
|
92
91
|
rootComponent: OnlyCustomEventsRootDoc,
|
|
93
92
|
});
|
|
94
93
|
|
|
94
|
+
// 2 rootComponent中只有customEvents字段时 加前缀(组件名) 无properties字段
|
|
95
95
|
type CompOnlyCustomEventsExpected = {
|
|
96
96
|
customEvents: {
|
|
97
97
|
test_str: string;
|
|
@@ -99,7 +99,7 @@ type CompOnlyCustomEventsExpected = {
|
|
|
99
99
|
test_unionStr: "male" | "female";
|
|
100
100
|
test_list: string | 0 | 1 | 2 | null;
|
|
101
101
|
test_bubbles: string | Bubbles;
|
|
102
|
-
test_capturePhase:
|
|
102
|
+
test_capturePhase: null | Capture;
|
|
103
103
|
test_bubbles_capturePhase: string | number | BubblesCapture;
|
|
104
104
|
test_bubbles_composed: "male" | "female" | BubblesComposed;
|
|
105
105
|
test_capturePhase_composed: string | 0 | 1 | 2 | CaptureComposed | null;
|
|
@@ -109,48 +109,19 @@ type CompOnlyCustomEventsExpected = {
|
|
|
109
109
|
|
|
110
110
|
Checking<typeof compOnlyCustomEvents, CompOnlyCustomEventsExpected, Test.Pass>;
|
|
111
111
|
|
|
112
|
-
// 都有
|
|
113
112
|
const rootComponent = RootComponent()({
|
|
114
113
|
properties,
|
|
115
114
|
customEvents,
|
|
116
115
|
});
|
|
117
|
-
|
|
116
|
+
// 3. properties和customEvents字段都有时
|
|
118
117
|
const compDoc = DefineComponent({
|
|
119
118
|
name: "test",
|
|
120
119
|
rootComponent,
|
|
121
120
|
});
|
|
122
121
|
|
|
123
|
-
Checking<typeof compDoc,
|
|
124
|
-
|
|
125
|
-
// rootComponent字段和SubComponents字段同时具有properties字段时
|
|
126
|
-
// const A = {} as { properties: { str: string; obj: { age: number } } };
|
|
127
|
-
|
|
128
|
-
// const B = {} as { properties: { num: number } };
|
|
129
|
-
|
|
130
|
-
// const C = {} as { properties: { bool: boolean } };
|
|
131
|
-
|
|
132
|
-
// const CompDoc = DefineComponent({
|
|
133
|
-
// name: "test",
|
|
134
|
-
// subComponents: [A, B, C],
|
|
135
|
-
// });
|
|
136
|
-
|
|
137
|
-
// // 因为子组件中properties不存在相同key,所以返回类型是交叉的。
|
|
138
|
-
// type CompDocExpect = ComputeIntersectionDeep<
|
|
139
|
-
// {
|
|
140
|
-
// properties: {
|
|
141
|
-
// test_str: string;
|
|
142
|
-
// test_obj: {
|
|
143
|
-
// age: number;
|
|
144
|
-
// } | null;
|
|
145
|
-
// test_num: number;
|
|
146
|
-
// test_bool: boolean;
|
|
147
|
-
// };
|
|
148
|
-
// }
|
|
149
|
-
// >;
|
|
150
|
-
|
|
151
|
-
// Checking<typeof CompDoc, CompDocExpect, Test.Pass>;
|
|
122
|
+
Checking<typeof compDoc, ComputeIntersection<CompOnlyCustomEventsExpected & OnlyPropertiesExpected>, Test.Pass>;
|
|
152
123
|
|
|
153
|
-
type
|
|
124
|
+
type SubA = SubComponentDoc<{
|
|
154
125
|
str: string | Bubbles | Composed;
|
|
155
126
|
num: number | Capture | Composed;
|
|
156
127
|
null: null | Bubbles | Capture | Composed;
|
|
@@ -158,10 +129,10 @@ type D = SubComponentDoc<{
|
|
|
158
129
|
|
|
159
130
|
const customEventsRootDoc = DefineComponent({
|
|
160
131
|
name: "test",
|
|
161
|
-
subComponents: [{} as
|
|
132
|
+
subComponents: [{} as SubA],
|
|
162
133
|
});
|
|
163
134
|
|
|
164
|
-
//
|
|
135
|
+
// 4 子组件返回的事件类型是必带Composed的
|
|
165
136
|
type customEventsRootDocExpect = {
|
|
166
137
|
customEvents: {
|
|
167
138
|
test_str: string | Bubbles | Composed;
|
|
@@ -172,19 +143,19 @@ type customEventsRootDocExpect = {
|
|
|
172
143
|
|
|
173
144
|
Checking<typeof customEventsRootDoc, customEventsRootDocExpect, Test.Pass>;
|
|
174
145
|
|
|
175
|
-
type
|
|
146
|
+
type SubB = SubComponentDoc<{
|
|
176
147
|
str: number | Bubbles | Composed;
|
|
177
148
|
num: string | Capture | Composed;
|
|
178
149
|
null: boolean | Bubbles | Capture | Composed;
|
|
179
150
|
}>;
|
|
180
151
|
|
|
181
|
-
//
|
|
152
|
+
//
|
|
182
153
|
const WhenSameKeyOfCustomEventsRootDoc = DefineComponent({
|
|
183
154
|
name: "test",
|
|
184
|
-
subComponents: [{} as
|
|
155
|
+
subComponents: [{} as SubA, {} as SubB],
|
|
185
156
|
});
|
|
186
157
|
|
|
187
|
-
//
|
|
158
|
+
// 5 子组件中存在相同自定义事件字段时,类型联合
|
|
188
159
|
type WhenSameKeyOfCustomEventsRootDocExpect = {
|
|
189
160
|
customEvents: {
|
|
190
161
|
test_str: string | number | Bubbles | Composed;
|
|
@@ -201,15 +172,16 @@ type RootDocCatch = RootComponentDoc<{
|
|
|
201
172
|
};
|
|
202
173
|
}>;
|
|
203
174
|
|
|
204
|
-
// 根组件有阻止(catch)子组件事件时
|
|
205
175
|
const whenRootDocCatch = DefineComponent({
|
|
206
176
|
name: "test",
|
|
207
177
|
rootComponent: {} as RootDocCatch,
|
|
208
|
-
subComponents: [{} as
|
|
178
|
+
subComponents: [{} as SubA],
|
|
209
179
|
});
|
|
210
180
|
|
|
181
|
+
// 6 根组件有阻止(catch)子组件事件时(子组件aaa的str事件是阻止事件,不会被继续传递),去除对应的事件
|
|
211
182
|
type whenRootDocCatchExpect = {
|
|
212
183
|
customEvents: {
|
|
184
|
+
// 少了str事件
|
|
213
185
|
test_num: number | Composed | Capture;
|
|
214
186
|
test_null: Bubbles | Composed | Capture | null;
|
|
215
187
|
};
|
|
@@ -217,7 +189,7 @@ type whenRootDocCatchExpect = {
|
|
|
217
189
|
|
|
218
190
|
Checking<typeof whenRootDocCatch, whenRootDocCatchExpect, Test.Pass>;
|
|
219
191
|
|
|
220
|
-
//
|
|
192
|
+
// 7 根组件和子组件都没有事件和properties时 返回组件类型为 {}
|
|
221
193
|
const ComponetDoc = DefineComponent({
|
|
222
194
|
name: "test",
|
|
223
195
|
rootComponent: {},
|
|
@@ -26,7 +26,7 @@ const compDocOnlyProperties = DefineComponent({
|
|
|
26
26
|
rootComponent: OnlyPropsRootDoc,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
// 页面时返回的propertiesDoc无前缀
|
|
29
|
+
// 1 页面时返回的propertiesDoc无前缀
|
|
30
30
|
type CompDocOnlyPropertiesExpected = {
|
|
31
31
|
path: "/pages/index/index";
|
|
32
32
|
properties: {
|
|
@@ -39,11 +39,11 @@ type CompDocOnlyPropertiesExpected = {
|
|
|
39
39
|
|
|
40
40
|
Checking<typeof compDocOnlyProperties, CompDocOnlyPropertiesExpected, Test.Pass>;
|
|
41
41
|
|
|
42
|
-
// 页面类型不受subComponents是[never,never]时影响
|
|
42
|
+
// 2 页面类型不受subComponents是[never,never]时影响
|
|
43
43
|
const whenSubIsAllNever = DefineComponent({
|
|
44
44
|
path: "/pages/index/index",
|
|
45
45
|
rootComponent: OnlyPropsRootDoc,
|
|
46
|
-
subComponents: [{} as never],
|
|
46
|
+
subComponents: [{} as never, {} as never],
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
Checking<typeof whenSubIsAllNever, CompDocOnlyPropertiesExpected, Test.Pass>;
|
|
@@ -10,15 +10,9 @@ import type { SubComponentDoc } from "../../SubComponent/SubComponentDoc";
|
|
|
10
10
|
*/
|
|
11
11
|
export type SubComponentsOption<
|
|
12
12
|
TSubComponentTuple extends SubComponentDoc[],
|
|
13
|
-
>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// PropertiesDuplicatedKeys,
|
|
20
|
-
// never,
|
|
21
|
-
// unknown,
|
|
22
|
-
// `⚠️重复的字段:${UnionToComma<PropertiesDuplicatedKeys>}⚠️`
|
|
23
|
-
// >;
|
|
24
|
-
};
|
|
13
|
+
> = {
|
|
14
|
+
/**
|
|
15
|
+
* 子组件列表
|
|
16
|
+
*/
|
|
17
|
+
subComponents?: [...TSubComponentTuple];
|
|
18
|
+
};
|
|
@@ -11,13 +11,13 @@ const NonEmptyRootDoc = {} as SubComponentDoc<{
|
|
|
11
11
|
a: string | Bubbles | Composed;
|
|
12
12
|
}>;
|
|
13
13
|
|
|
14
|
-
// 组件时
|
|
14
|
+
// 1 组件时
|
|
15
15
|
DefineComponent({
|
|
16
16
|
name: "test",
|
|
17
17
|
subComponents: [SubDocIsAny, NonEmptyRootDoc],
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
// 页面时
|
|
20
|
+
// 2 页面时
|
|
21
21
|
DefineComponent({
|
|
22
22
|
path: "/test/index/index",
|
|
23
23
|
rootComponent: { isPage: true },
|
|
@@ -30,10 +30,9 @@ const B = {} as { a: string | Composed; b: string | Composed };
|
|
|
30
30
|
|
|
31
31
|
const C = {} as { a: boolean | Composed; c: boolean | Composed };
|
|
32
32
|
|
|
33
|
-
// subComponents字段支持最多999个子组件
|
|
34
33
|
const aaa = DefineComponent({
|
|
35
34
|
name: "test",
|
|
36
|
-
//
|
|
35
|
+
// 3 subComponents字段支持最多999个子组件
|
|
37
36
|
subComponents: [
|
|
38
37
|
A,
|
|
39
38
|
B,
|
|
@@ -22,7 +22,7 @@ type RootOptions<
|
|
|
22
22
|
TName extends string,
|
|
23
23
|
TPath extends Path,
|
|
24
24
|
> =
|
|
25
|
-
& NameOrPathOption<TName, TPath, TRootComponentDoc>
|
|
25
|
+
& NameOrPathOption<TName, TPath, TRootComponentDoc["isPage"] & {}>
|
|
26
26
|
& RootComponentOption<TRootComponentDoc>
|
|
27
27
|
& SubComponentsOption<TSubComponentTuple>;
|
|
28
28
|
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { Select } from "hry-types/src/Object/Select";
|
|
3
2
|
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
4
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
5
|
-
import type { OptionalType
|
|
4
|
+
import type { OptionalType } from "./PropertiesConstraint";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* 获取properties可传字段文档类型
|
|
9
8
|
*/
|
|
10
9
|
export type GetOptionalDoc<
|
|
11
|
-
|
|
10
|
+
TOptionalProperties extends Record<string, OptionalType>,
|
|
12
11
|
TIsPage extends boolean,
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
Optional extends Record<string, OptionalType> = Select<TProperties, OptionalType>,
|
|
15
12
|
> = {
|
|
16
|
-
[k in keyof
|
|
13
|
+
-readonly [k in keyof TOptionalProperties]?: IfExtends<
|
|
17
14
|
unknown,
|
|
18
|
-
|
|
15
|
+
TOptionalProperties[k]["optionalTypes"],
|
|
19
16
|
IfExtends<
|
|
20
17
|
false,
|
|
21
18
|
TIsPage,
|
|
22
19
|
// 组件时 对象加null
|
|
23
|
-
AddNullForObject<InferDetailedType<
|
|
20
|
+
AddNullForObject<InferDetailedType<TOptionalProperties[k]["type"]>>,
|
|
24
21
|
// 页面时 对象不加
|
|
25
|
-
InferDetailedType<
|
|
22
|
+
InferDetailedType<TOptionalProperties[k]["type"]>
|
|
26
23
|
>,
|
|
27
24
|
IfExtends<
|
|
28
25
|
false,
|
|
29
26
|
TIsPage,
|
|
30
27
|
// 组件时 对象加null
|
|
31
28
|
AddNullForObject<
|
|
32
|
-
|
|
29
|
+
| InferDetailedType<TOptionalProperties[k]["type"]>
|
|
30
|
+
| InferDetailedType<(TOptionalProperties[k]["optionalTypes"] & {})[number]>
|
|
33
31
|
>,
|
|
34
32
|
// 页面时 对象不加
|
|
35
|
-
|
|
33
|
+
| InferDetailedType<TOptionalProperties[k]["type"]>
|
|
34
|
+
| InferDetailedType<(TOptionalProperties[k]["optionalTypes"] & {})[number]>
|
|
36
35
|
>
|
|
37
36
|
>;
|
|
38
37
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
1
|
import type { Select } from "hry-types/src/Object/Select";
|
|
3
2
|
|
|
4
|
-
import type { ComputeIntersection
|
|
3
|
+
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
5
4
|
import type { GetOptionalDoc } from "./GetOptionalDoc";
|
|
6
5
|
import type { GetRequiredDoc } from "./GetRequiredDoc";
|
|
7
6
|
import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
|
|
@@ -9,25 +8,16 @@ import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint"
|
|
|
9
8
|
type _GetPropertiesDoc<
|
|
10
9
|
TProperties extends PropertiesConstraint,
|
|
11
10
|
TIsPage extends boolean,
|
|
12
|
-
Type extends "Required" | "Optional" | "all" = "all",
|
|
13
|
-
OptionalDoc = NonReadonlyDeep<GetOptionalDoc<Select<TProperties, OptionalType>, TIsPage>>,
|
|
14
|
-
RequiredDoc = NonReadonlyDeep<GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>, TIsPage>>,
|
|
15
|
-
> = IfExtends<
|
|
16
|
-
Type,
|
|
17
|
-
"all",
|
|
18
11
|
// @ts-ignore
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
OptionalDoc extends object = GetOptionalDoc<Select<TProperties, OptionalType>, TIsPage>,
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
RequiredDoc extends object = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>, TIsPage>,
|
|
15
|
+
> = ComputeIntersection<OptionalDoc & RequiredDoc>;
|
|
22
16
|
|
|
23
17
|
/**
|
|
24
18
|
* properties字段的文档类型
|
|
25
|
-
* @param TProperties - `PropertiesConstraint`
|
|
26
|
-
* @param Type - "Required" | "Optional" | "all"
|
|
27
|
-
* @returns `GetRequiredDoc` | `GetOptionalDoc` | (`GetOptionalDoc` & `GetRequiredDoc`)
|
|
28
19
|
*/
|
|
29
20
|
export type GetPropertiesDoc<
|
|
30
21
|
TProperties extends PropertiesConstraint,
|
|
31
22
|
TisPage extends boolean,
|
|
32
|
-
|
|
33
|
-
> = _GetPropertiesDoc<TProperties, TisPage, Type>;
|
|
23
|
+
> = _GetPropertiesDoc<TProperties, TisPage>;
|
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { Select } from "hry-types/src/Object/Select";
|
|
3
2
|
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
4
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
5
|
-
import type {
|
|
4
|
+
import type { RequiredSingle, RequiredType } from "./PropertiesConstraint";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* 获取properties必传字段的文档类型
|
|
9
|
-
* @remarks 小程序中必传字段如果是object,默认类型为null
|
|
8
|
+
* @remarks 小程序中必传字段如果是object,默认类型为null,所以组件文档对象类型要联合上null类型
|
|
10
9
|
*/
|
|
11
10
|
export type GetRequiredDoc<
|
|
12
|
-
TProperties extends
|
|
11
|
+
TProperties extends Record<string, RequiredType>,
|
|
13
12
|
TIsPage extends boolean,
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
Required extends Record<string, RequiredType> = Select<TProperties, RequiredType>,
|
|
16
13
|
> = {
|
|
17
|
-
[k in keyof
|
|
18
|
-
|
|
14
|
+
-readonly [k in keyof TProperties]: IfExtends<
|
|
15
|
+
TProperties[k],
|
|
16
|
+
// 非对象写法
|
|
19
17
|
RequiredSingle,
|
|
20
|
-
IfExtends<false, TIsPage, AddNullForObject<InferDetailedType<Required[k]>>, InferDetailedType<Required[k]>>,
|
|
21
18
|
IfExtends<
|
|
22
19
|
false,
|
|
23
20
|
TIsPage,
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
// 组件的对象类型加null
|
|
22
|
+
AddNullForObject<InferDetailedType<TProperties[k]>>,
|
|
23
|
+
// 页面的对象类型不加null
|
|
24
|
+
InferDetailedType<TProperties[k]>
|
|
25
|
+
>,
|
|
26
|
+
// 对象写法 RequiredUnion
|
|
27
|
+
IfExtends<
|
|
28
|
+
false,
|
|
29
|
+
TIsPage,
|
|
30
|
+
// 组件的对象类型加null
|
|
31
|
+
AddNullForObject<
|
|
32
|
+
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
33
|
+
| InferDetailedType<TProperties[k]["type"]>
|
|
34
|
+
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
35
|
+
| InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
36
|
+
>,
|
|
37
|
+
// 页面的对象类型不加null
|
|
38
|
+
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
39
|
+
InferDetailedType<TProperties[k]["type"]> | InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
30
40
|
>
|
|
31
41
|
>;
|
|
32
42
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Checking, type Test } from "hry-types";
|
|
1
2
|
import { observable } from "mobx";
|
|
2
3
|
import { RootComponent } from "../..";
|
|
3
4
|
const user = observable({
|
|
@@ -5,9 +6,18 @@ const user = observable({
|
|
|
5
6
|
age: 20,
|
|
6
7
|
});
|
|
7
8
|
|
|
8
|
-
RootComponent()({
|
|
9
|
+
const storeDoc = RootComponent()({
|
|
9
10
|
store: {
|
|
10
11
|
userName: () => user.name,
|
|
11
12
|
userAge: () => user.age,
|
|
12
13
|
},
|
|
13
14
|
});
|
|
15
|
+
|
|
16
|
+
type StoreDocExpected = {
|
|
17
|
+
store: {
|
|
18
|
+
userName: string;
|
|
19
|
+
userAge: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Checking<typeof storeDoc, StoreDocExpected, Test.Pass>;
|
|
@@ -2,7 +2,8 @@ import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
|
2
2
|
import type { NoInfer } from "hry-types/src/Generic/NoInfer";
|
|
3
3
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
4
4
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
6
|
+
import type { ComputeObject } from "../../types/ComputeObj";
|
|
6
7
|
import type { WMCompOtherOption, WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
|
|
7
8
|
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
|
|
8
9
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
@@ -111,16 +112,16 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
|
|
|
111
112
|
StoreDoc,
|
|
112
113
|
ComputedDoc
|
|
113
114
|
>,
|
|
114
|
-
): // 返回类型 RootComponentDoc
|
|
115
|
-
|
|
115
|
+
): // 返回类型 satisfies RootComponentDoc
|
|
116
|
+
ComputeIntersection<
|
|
116
117
|
& IfExtends<TIsPage, false, {}, { isPage: true }>
|
|
117
118
|
& IfExtends<EmptyObject, PropertiesDoc, {}, { properties: PropertiesDoc }>
|
|
118
119
|
& IfExtends<EmptyObject, DataDoc, {}, { data: DataDoc }>
|
|
119
|
-
& IfExtends<EmptyObject, StoreDoc, {}, { store: StoreDoc }>
|
|
120
|
+
& IfExtends<EmptyObject, StoreDoc, {}, { store: ComputeObject<StoreDoc> }>
|
|
120
121
|
& IfExtends<EmptyObject, ComputedDoc, {}, { computed: ComputedDoc }>
|
|
121
122
|
& IfExtends<EmptyObject, TMethods, {}, { methods: TMethods }>
|
|
122
123
|
& IfExtends<EmptyObject, EventsDoc, {}, { events: EventsDoc }>
|
|
123
|
-
& IfExtends<EmptyObject, CustomEventsDoc, {}, { customEvents: CustomEventsDoc }>
|
|
124
|
+
& IfExtends<EmptyObject, CustomEventsDoc, {}, { customEvents: ComputeObject<CustomEventsDoc> }>
|
|
124
125
|
>;
|
|
125
126
|
};
|
|
126
127
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
3
|
import type { Wm } from "../../../../thirdLib";
|
|
4
|
-
import type {
|
|
4
|
+
import type { ComponentDocExtension } from "../../../../types/ComponentDocExtension";
|
|
5
5
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
6
6
|
|
|
7
7
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
@@ -28,7 +28,10 @@ SubComponent<{}, CompDoc>()({
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// 2. 使用CompDocExtends泛型拓展组件文档,满足内部组件内部包含一些slot或基本组件数据
|
|
31
|
-
type viewExtends =
|
|
31
|
+
type viewExtends = ComponentDocExtension<
|
|
32
|
+
Wm.View,
|
|
33
|
+
{ properties: { view_obj: Mock_User | null; view_str: string; view_ddd: number } }
|
|
34
|
+
>;
|
|
32
35
|
|
|
33
36
|
const res = SubComponent<{}, viewExtends>()({
|
|
34
37
|
inherit: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
3
|
import type { RequiredKeys } from "hry-types/src/Object/RequiredKeys";
|
|
4
|
-
import type {
|
|
4
|
+
import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
|
|
5
5
|
import type { ReplacePrefix } from "../../types/ReplacePrefix";
|
|
6
6
|
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
|
|
7
7
|
|
|
@@ -95,7 +95,7 @@ type SubComponentConstructor<
|
|
|
95
95
|
TSupplementalPrefix extends string = "",
|
|
96
96
|
IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false,
|
|
97
97
|
// 重构子组件的前缀
|
|
98
|
-
CurrentPrefix extends string = `${
|
|
98
|
+
CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`,
|
|
99
99
|
// 更新原始文档的前缀为Prefix
|
|
100
100
|
CurrentCompDoc extends ComponentDoc = IfExtends<
|
|
101
101
|
TSupplementalPrefix,
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export type { Vant, Wm } from "./thirdLib";
|
|
2
|
-
|
|
3
|
-
export type { Dataset, Detail, WMBaseEvent, WMCustomEvent } from "./types/OfficialTypeAlias";
|
|
4
|
-
|
|
5
1
|
import { navigateTo } from "./api/navigateTo";
|
|
6
2
|
|
|
7
3
|
import { DefineComponent } from "./api/DefineComponent";
|
|
@@ -12,10 +8,15 @@ import { SubComponent } from "./api/SubComponent";
|
|
|
12
8
|
|
|
13
9
|
import type { DetailedType } from "./types/DetailedType";
|
|
14
10
|
|
|
11
|
+
import type { ComponentDocExtension } from "./types/ComponentDocExtension";
|
|
15
12
|
import type { GenerateDoc } from "./types/GenerateDoc";
|
|
16
13
|
import type { ParamsEqual } from "./types/TwoParamsEqual";
|
|
14
|
+
export type { Vant, Wm } from "./thirdLib";
|
|
15
|
+
|
|
16
|
+
export type { Dataset, Detail, WMBaseEvent, WMCustomEvent } from "./types/OfficialTypeAlias";
|
|
17
17
|
|
|
18
18
|
export {
|
|
19
|
+
type ComponentDocExtension,
|
|
19
20
|
DefineComponent,
|
|
20
21
|
type DetailedType,
|
|
21
22
|
type GenerateDoc,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
+
import type { ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
|
|
3
|
+
import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
|
|
4
|
+
import type { GetComponentPrefix } from "./GetComponentPrefix";
|
|
5
|
+
|
|
6
|
+
type Validator<
|
|
7
|
+
TOriginalComponentDoc extends ComponentDoc,
|
|
8
|
+
TExtensionDoc extends ComponentDoc,
|
|
9
|
+
TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentDoc>,
|
|
10
|
+
TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionDoc>,
|
|
11
|
+
DuplicateKeys extends PropertyKey =
|
|
12
|
+
| Extract<keyof TExtensionDoc["properties"], keyof TOriginalComponentDoc["properties"]>
|
|
13
|
+
| Extract<keyof TExtensionDoc["customEvents"], keyof TOriginalComponentDoc["customEvents"]>,
|
|
14
|
+
> = IfExtends<
|
|
15
|
+
TOriginalPrefix,
|
|
16
|
+
TExtenstionPrefix,
|
|
17
|
+
IfExtends<DuplicateKeys, never, ComponentDoc, `${DuplicateKeys & string}字段重复`>,
|
|
18
|
+
`前缀错误,应为${TOriginalPrefix & string}`
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 有时组件文档内部包含一些slot或基本组件,可通过CompDocExtends泛型拓展组件文档,使得类型更安全
|
|
23
|
+
*/
|
|
24
|
+
export type ComponentDocExtension<
|
|
25
|
+
TOriginalComponentDoc extends ComponentDoc,
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
TExtensionDoc extends Validator<TOriginalComponentDoc, TExtensionDoc>,
|
|
28
|
+
> = ComputeIntersectionDeep<TOriginalComponentDoc & TExtensionDoc>;
|
|
29
|
+
|
|
30
|
+
// type test0 = ComponentDocExtension<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
31
|
+
|
|
32
|
+
// type test1 = ComponentDocExtension<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
33
|
+
|
|
34
|
+
// type test2 = ComponentDocExtension<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
35
|
+
|
|
36
|
+
// type test3 = ComponentDocExtension<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ComputeObject<T> = T extends unknown ? { [k in keyof T]: T[k] } : never;
|
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
// import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
3
|
+
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
4
|
import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 提取文档前缀名
|
|
7
|
-
* @param TComponentDoc - ComponentDoc
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export type GetComponentPrefix<TComponentDoc extends ComponentDoc> = EmptyObject extends TComponentDoc ? never
|
|
10
|
+
: keyof IfExtends<
|
|
11
|
+
unknown,
|
|
12
|
+
TComponentDoc["properties"],
|
|
13
|
+
TComponentDoc["customEvents"],
|
|
14
|
+
TComponentDoc["properties"]
|
|
15
|
+
> extends `${infer P}_${string}` ? P
|
|
16
|
+
: never;
|
|
16
17
|
|
|
17
|
-
// type Test1 =
|
|
18
|
+
// type Test1 = GetComponentPrefix<{ properties: { xxx_name: string } }>;
|
|
18
19
|
|
|
19
20
|
// type Test1Expect = "xxx";
|
|
20
21
|
|
|
21
22
|
// Checking<Test1, Test1Expect, Test.Pass>;
|
|
22
23
|
|
|
23
|
-
// type Test2 =
|
|
24
|
+
// type Test2 = GetComponentPrefix<{ customEvents: { xxx_name: string } }>;
|
|
24
25
|
|
|
25
26
|
// type Test2Expect = "xxx";
|
|
26
27
|
|
|
27
28
|
// Checking<Test2, Test2Expect, Test.Pass>;
|
|
28
29
|
|
|
29
|
-
//
|
|
30
|
-
// type Test3 = ExtractDocPrefix<{}>;
|
|
30
|
+
// type demo = never extends `${infer P}_${string}` ? P : ""; // => string why?
|
|
31
31
|
|
|
32
|
-
// type
|
|
32
|
+
// type Test3 = GetComponentPrefix<{}>;
|
|
33
|
+
|
|
34
|
+
// type Test3Expect = never;
|
|
33
35
|
|
|
34
36
|
// Checking<Test3, Test3Expect, Test.Pass>;
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.test.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/SubComponents/test/error.test.ts"],"names":[],"mappings":""}
|