annil 1.5.14 → 1.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/api/SubComponent/SubComputed/SubComputedOption.d.ts +2 -2
- package/dist/api/SubComponent/index.d.ts +4 -4
- package/dist/api/SubComponent/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +2 -2
- package/src/api/SubComponent/SubComputed/test/error.test.ts +13 -0
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +13 -0
- package/src/api/SubComponent/index.ts +29 -18
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
* 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
|
|
6
6
|
|
|
7
|
+
## [1.5.15](https://github.com/missannil/annil/compare/v1.5.14...v1.5.15) (2024-01-15)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* subComputed约束 去除默认{} ([054cb48](https://github.com/missannil/annil/commit/054cb482cdc6c84e820d69d163b9cafe0c01de81))
|
|
13
|
+
|
|
7
14
|
## [1.5.14](https://github.com/missannil/annil/compare/v1.5.13...v1.5.14) (2024-01-15)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
|
-
export type SubComputedOption<TComputed extends object, legal extends
|
|
3
|
-
computed?: TComputed & V.IllegalFieldValidator<TComputed,
|
|
2
|
+
export type SubComputedOption<TComputed extends object, legal extends PropertyKey> = {
|
|
3
|
+
computed?: TComputed & V.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
4
4
|
};
|
|
@@ -37,11 +37,11 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
|
|
|
37
37
|
import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
|
|
38
38
|
import type { SubStoreOption } from "./SubStore/SubStoreOption";
|
|
39
39
|
import type { SubWatchOption } from "./SubWatch/SubWatchOption";
|
|
40
|
-
type Options<RootDoc extends RootComponentDoc, IsPage extends boolean, CurrentCompDoc extends ComponentDoc, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object
|
|
40
|
+
type Options<RootDoc extends RootComponentDoc, IsPage extends boolean, CurrentCompDoc extends ComponentDoc, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object, CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"]> = SubInheritOption<TInherit, CompDocKeys> & SubDataOption<TSubData, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof InheritDoc)>, Prefix> & SubStoreOption<TSubStore, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>, Prefix> & SubComputedOption<TSubComputed, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & SubLifetimesOption & SubWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & SubObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<SubInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
|
|
41
41
|
type SubComponentConstructor<TRootDoc extends RootComponentDoc, TOriginalCompDoc extends ComponentDoc, TSupplementalPrefix extends string = "", IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false, CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`, CurrentCompDoc extends ComponentDoc = IfExtends<TSupplementalPrefix, "", TOriginalCompDoc, ReplacePrefix<TOriginalCompDoc, CurrentPrefix>>, AllRootDataDoc extends object = Required<TRootDoc["properties"]> & TRootDoc["data"] & TRootDoc["computed"] & TRootDoc["store"]> = {
|
|
42
|
-
<TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]
|
|
43
|
-
[k in keyof TSubStore]: ReturnType<TSubStore[k]
|
|
44
|
-
}>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<CurrentCompDoc["properties"]
|
|
42
|
+
<TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore, {}, {
|
|
43
|
+
[k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>>;
|
|
44
|
+
}>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>, keyof (InheritDoc & SubDataDoc & SubStoreDoc & IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>)>>(options: Options<TRootDoc, IsPage, CurrentCompDoc, CurrentPrefix, AllRootDataDoc, TInherit, TSubData, TSubStore, TSubComputed, TEvents, TSubMethods, InheritDoc, SubDataDoc, SubStoreDoc, SubComputedDoc, SubEventsDoc, SubMethodsDoc>): CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
|
|
45
45
|
};
|
|
46
46
|
export declare function SubComponent<RootDoc extends RootComponentDoc, CompDoc extends ComponentDoc, Prefix extends string = "">(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>>;
|
|
47
47
|
export type SubComponentTrueOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"AAyOA,MAAM,UAAU,YAAY;IAK1B,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAkC,CAAQ,CAAC;AACvE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
export type SubComputedOption<
|
|
3
3
|
TComputed extends object,
|
|
4
|
-
legal extends
|
|
4
|
+
legal extends PropertyKey,
|
|
5
5
|
> = {
|
|
6
6
|
computed?:
|
|
7
7
|
& TComputed
|
|
8
|
-
& V.IllegalFieldValidator<TComputed,
|
|
8
|
+
& V.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
9
9
|
};
|
|
@@ -48,3 +48,16 @@ SubComponent<{}, OnlyPropsCompDoc>()({
|
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
// 4 类型错误
|
|
53
|
+
SubComponent<{}, OnlyPropsCompDoc>()({
|
|
54
|
+
data: {
|
|
55
|
+
aaa_isReady: false,
|
|
56
|
+
},
|
|
57
|
+
computed: {
|
|
58
|
+
// @ts-ignore 重复的字段
|
|
59
|
+
aaa_isReady() {
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
@@ -140,5 +140,18 @@ SubComponent<Root, $aaa>()({
|
|
|
140
140
|
aaa_str(): string {
|
|
141
141
|
return this.data.str;
|
|
142
142
|
},
|
|
143
|
+
|
|
144
|
+
aaa_isReady() {
|
|
145
|
+
return false;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
SubComponent<Root, $aaa>()({
|
|
151
|
+
computed: {
|
|
152
|
+
// 可以写isReady字段 ExtraFields
|
|
153
|
+
aaa_isReady() {
|
|
154
|
+
return false;
|
|
155
|
+
},
|
|
143
156
|
},
|
|
144
157
|
});
|
|
@@ -57,28 +57,28 @@ type Options<
|
|
|
57
57
|
SubComputedDoc extends object,
|
|
58
58
|
SubEventsDoc extends object,
|
|
59
59
|
SubMethodsDoc extends object,
|
|
60
|
+
CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"],
|
|
60
61
|
> =
|
|
61
|
-
& SubInheritOption<TInherit,
|
|
62
|
+
& SubInheritOption<TInherit, CompDocKeys>
|
|
62
63
|
& SubDataOption<
|
|
63
64
|
TSubData,
|
|
64
|
-
Exclude<
|
|
65
|
+
Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof InheritDoc)>,
|
|
65
66
|
Prefix
|
|
66
67
|
>
|
|
67
68
|
& SubStoreOption<
|
|
68
69
|
TSubStore,
|
|
69
|
-
Exclude<
|
|
70
|
+
Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>,
|
|
70
71
|
Prefix
|
|
71
72
|
>
|
|
72
73
|
& SubComputedOption<
|
|
73
74
|
TSubComputed,
|
|
74
|
-
// AllRootDataDoc & SubDataDoc & SubDataDoc & SubComputedDoc,
|
|
75
75
|
// 合法的配置
|
|
76
|
-
|
|
76
|
+
Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>
|
|
77
77
|
>
|
|
78
78
|
// 无需与根组件的events字段重复检测,因为根组件多了bubbles字段,一定不会重复
|
|
79
79
|
& SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>>
|
|
80
80
|
& SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)>
|
|
81
|
-
& SubPageLifetimesOption<IsPage, RootDoc["properties"]
|
|
81
|
+
& SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>>
|
|
82
82
|
& SubLifetimesOption
|
|
83
83
|
& SubWatchOption<
|
|
84
84
|
& SubComputedDoc
|
|
@@ -100,7 +100,7 @@ type Options<
|
|
|
100
100
|
SubMethodsDoc & RootDoc["methods"],
|
|
101
101
|
Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>,
|
|
102
102
|
AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>,
|
|
103
|
-
RootDoc["customEvents"]
|
|
103
|
+
NonNullable<RootDoc["customEvents"]>,
|
|
104
104
|
SubStoreDoc
|
|
105
105
|
>
|
|
106
106
|
>;
|
|
@@ -130,8 +130,7 @@ type SubComponentConstructor<
|
|
|
130
130
|
<
|
|
131
131
|
TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>,
|
|
132
132
|
TSubData extends SubDataConstraint<
|
|
133
|
-
& Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>
|
|
134
|
-
& Extra<CurrentPrefix> // 加入特许字段 isReady
|
|
133
|
+
& Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc>
|
|
135
134
|
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
136
135
|
>,
|
|
137
136
|
TSubStore extends SubStoreConstraint<
|
|
@@ -141,28 +140,40 @@ type SubComponentConstructor<
|
|
|
141
140
|
TEvents extends SubEventsConstraint<CurrentCompDoc>,
|
|
142
141
|
// 加默认值计算字段无提示且需要手写返回类型,不加watch无法对computed监控
|
|
143
142
|
TSubComputed extends SubComputedConstraint<
|
|
144
|
-
& Omit<
|
|
145
|
-
|
|
143
|
+
& Omit<
|
|
144
|
+
Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>,
|
|
145
|
+
keyof (InheritDoc & SubDataDoc & SubStoreDoc)
|
|
146
|
+
>
|
|
146
147
|
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
147
|
-
|
|
148
|
+
>,
|
|
148
149
|
TSubMethods extends SubMethodsConstraint = {},
|
|
149
150
|
InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>,
|
|
150
151
|
SubDataDoc extends object = IfExtends<
|
|
151
|
-
SubDataConstraint<
|
|
152
|
+
SubDataConstraint<
|
|
153
|
+
& Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc>
|
|
154
|
+
& Record<InnerFields<CurrentPrefix>, unknown>
|
|
155
|
+
>,
|
|
152
156
|
TSubData,
|
|
153
157
|
{},
|
|
154
158
|
TSubData
|
|
155
159
|
>,
|
|
156
160
|
SubStoreDoc extends object = IfExtends<
|
|
157
|
-
SubStoreConstraint<
|
|
161
|
+
SubStoreConstraint<
|
|
162
|
+
& Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)>
|
|
163
|
+
& Record<InnerFields<CurrentPrefix>, unknown>
|
|
164
|
+
>,
|
|
158
165
|
TSubStore,
|
|
159
166
|
{},
|
|
160
|
-
{ [k in keyof TSubStore]: ReturnType<TSubStore[k]
|
|
167
|
+
{ [k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>> }
|
|
161
168
|
>,
|
|
162
169
|
// 无效的计算
|
|
163
170
|
SubComputedDoc extends object = IfExtends<
|
|
164
171
|
SubComputedConstraint<
|
|
165
|
-
Omit<
|
|
172
|
+
& Omit<
|
|
173
|
+
Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>,
|
|
174
|
+
keyof (InheritDoc & SubDataDoc & SubStoreDoc)
|
|
175
|
+
>
|
|
176
|
+
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
166
177
|
>,
|
|
167
178
|
TSubComputed,
|
|
168
179
|
{},
|
|
@@ -177,7 +188,7 @@ type SubComponentConstructor<
|
|
|
177
188
|
SubMethodsDoc extends object = TSubMethods,
|
|
178
189
|
// 缺失的必传字段(配置中inhrit,data,computed的字段不包含的必传字段)
|
|
179
190
|
MissingRequiredField extends PropertyKey = Exclude<
|
|
180
|
-
RequiredKeys<CurrentCompDoc["properties"]
|
|
191
|
+
RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>,
|
|
181
192
|
keyof (
|
|
182
193
|
& InheritDoc
|
|
183
194
|
& SubDataDoc
|
|
@@ -213,7 +224,7 @@ type SubComponentConstructor<
|
|
|
213
224
|
SubEventsDoc,
|
|
214
225
|
SubMethodsDoc
|
|
215
226
|
>,
|
|
216
|
-
): CreateSubComponentDoc<TOriginalCompDoc["customEvents"]
|
|
227
|
+
): CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
|
|
217
228
|
};
|
|
218
229
|
|
|
219
230
|
/**
|