annil 1.5.12 → 1.5.14
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/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +2 -1
- package/dist/api/SubComponent/SubData/SubDataOption.d.ts +2 -1
- package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +3 -2
- package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +3 -2
- package/dist/api/SubComponent/index.d.ts +4 -2
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/types/Extra.d.ts +1 -0
- package/dist/types/Extra.js +2 -0
- package/dist/types/Extra.js.map +1 -0
- package/dist/types/InnerData.d.ts +1 -0
- package/dist/types/InnerData.js +2 -0
- package/dist/types/InnerData.js.map +1 -0
- package/package.json +1 -1
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +3 -1
- package/src/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.ts +8 -1
- package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +8 -0
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +23 -0
- package/src/api/SubComponent/SubData/SubDataOption.ts +3 -2
- package/src/api/SubComponent/SubData/test/normal.test.ts +12 -2
- package/src/api/SubComponent/SubInherit/SubInheritOption.ts +11 -2
- package/src/api/SubComponent/SubInherit/test/error.test.ts +12 -0
- package/src/api/SubComponent/SubStore/SubStoreOption.ts +4 -3
- package/src/api/SubComponent/SubStore/test/error.test.ts +5 -0
- package/src/api/SubComponent/SubStore/test/normal.test.ts +9 -7
- package/src/api/SubComponent/index.ts +18 -6
- package/src/types/Extra.ts +1 -0
- package/src/types/InnerData.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
* 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
|
|
6
6
|
|
|
7
|
+
## [1.5.14](https://github.com/missannil/annil/compare/v1.5.13...v1.5.14) (2024-01-15)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* subComponents的data字段和store字段加入isReady字段和内部字段 ([06a22e0](https://github.com/missannil/annil/commit/06a22e0faff21dbc1e96862f190b2af11db55603))
|
|
13
|
+
|
|
14
|
+
## [1.5.13](https://github.com/missannil/annil/compare/v1.5.12...v1.5.13) (2024-01-12)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* 修改自定义事件detail类型为ReadOnlyDeep,以便调用时可传入实例中的data类型(都是ReadOnlyDeep的) ([428710e](https://github.com/missannil/annil/commit/428710ea84717c45361d1e6c9c7db46c693026a9))
|
|
20
|
+
|
|
7
21
|
## [1.5.12](https://github.com/missannil/annil/compare/v1.5.11...v1.5.12) (2024-01-12)
|
|
8
22
|
|
|
9
23
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
1
2
|
import type { DetailedType } from "../../../types/DetailedType";
|
|
2
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
4
|
import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents, SimpleCustomeEventsList } from "./CustomEventConstraint";
|
|
4
5
|
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
5
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T
|
|
6
|
+
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? ReadonlyDeep<InferDetailedType<T>> : T extends null ? null : T extends undefined ? undefined : T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]> : never;
|
|
6
7
|
export type GetFullCustomEventsDoc<T extends FullCustomEvents> = GetShortCustomEventsDoc<T["detail"]> | AddTagForCustomEventsDoc<T["options"]>;
|
|
7
8
|
export type GetCustomEventDoc<T extends CustomEventConstraint> = {
|
|
8
9
|
[k in keyof T]: T[k] extends ShortCustomeEvents ? GetShortCustomEventsDoc<T[k]> : GetShortCustomEventsDoc<T[k]["detail"]> | AddTagForCustomEventsDoc<T[k]["options"]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
|
+
import type { InnerFields } from "../../../types/InnerData";
|
|
2
3
|
export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
|
|
3
|
-
data?: TSubData & V.IllegalFieldValidator<TSubData, legalKeys |
|
|
4
|
+
data?: TSubData & V.IllegalFieldValidator<TSubData, legalKeys | InnerFields<TPrefix>, 0, "", "子组件无需此字段或与Inherit字段重复">;
|
|
4
5
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { V } from "hry-types";
|
|
2
|
+
export type SubInheritOption<TInherit extends object, legalKeys extends PropertyKey> = {
|
|
3
|
+
inherit?: TInherit & V.IllegalFieldValidator<TInherit, legalKeys, 0, "">;
|
|
3
4
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { InnerFields } from "../../../types/InnerData";
|
|
3
|
+
export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
|
|
4
|
+
store?: TSubStore & V.IllegalFieldValidator<TSubStore, legalKeys | InnerFields<TPrefix>, 0, "", "与inherit和data字段重复或前缀错误">;
|
|
4
5
|
};
|
|
@@ -5,6 +5,8 @@ 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
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
8
|
+
import type { Extra } from "../../types/Extra";
|
|
9
|
+
import type { InnerFields } from "../../types/InnerData";
|
|
8
10
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
9
11
|
import type { Replace } from "../../types/Replace";
|
|
10
12
|
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
@@ -35,9 +37,9 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
|
|
|
35
37
|
import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
|
|
36
38
|
import type { SubStoreOption } from "./SubStore/SubStoreOption";
|
|
37
39
|
import type { SubWatchOption } from "./SubWatch/SubWatchOption";
|
|
38
|
-
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> = SubInheritOption<TInherit> & SubDataOption<TSubData, Exclude<keyof CurrentCompDoc["properties"]
|
|
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> = SubInheritOption<TInherit, keyof CurrentCompDoc["properties"]> & SubDataOption<TSubData, Exclude<keyof CurrentCompDoc["properties"] | keyof Extra<Prefix>, (keyof InheritDoc)>, Prefix> & SubStoreOption<TSubStore, Exclude<keyof CurrentCompDoc["properties"] | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>, Prefix> & SubComputedOption<TSubComputed, Omit<CurrentCompDoc["properties"], (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, 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"]>>, RootDoc["customEvents"] & {}, SubStoreDoc>>;
|
|
39
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"]> = {
|
|
40
|
-
<TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>> = {}, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>, TSubStore, {}, {
|
|
42
|
+
<TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc> & Extra<CurrentPrefix> & 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"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Extra<CurrentPrefix> & 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"]>, keyof InheritDoc>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>, TSubStore, {}, {
|
|
41
43
|
[k in keyof TSubStore]: ReturnType<TSubStore[k] & {}>;
|
|
42
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"] & {}>, 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<TOriginalCompDoc["customEvents"] & {}, SubEventsDoc, MissingRequiredField>;
|
|
43
45
|
};
|
|
@@ -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":"AA8NA,MAAM,UAAU,YAAY;IAK1B,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAkC,CAAQ,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Extra<Prefix extends string> = Record<`${Prefix}_isReady`, boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extra.js","sourceRoot":"","sources":["../../src/types/Extra.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type InnerFields<Prefix extends string> = `_${Prefix}_${string}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InnerData.js","sourceRoot":"","sources":["../../src/types/InnerData.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
1
2
|
import type { DetailedType } from "../../../types/DetailedType";
|
|
2
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
4
|
import type {
|
|
@@ -8,7 +9,8 @@ import type {
|
|
|
8
9
|
} from "./CustomEventConstraint";
|
|
9
10
|
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
10
11
|
|
|
11
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType
|
|
12
|
+
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType
|
|
13
|
+
? ReadonlyDeep<InferDetailedType<T>>
|
|
12
14
|
: T extends null ? null
|
|
13
15
|
: T extends undefined ? undefined
|
|
14
16
|
: T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]>
|
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
type CapturePhaseComposedExpected,
|
|
10
10
|
type CapturePhaseExpected,
|
|
11
11
|
} from "./GetFullEventDoc.test";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type ListExpected,
|
|
14
|
+
type NullExpected,
|
|
15
|
+
type ObjExpected,
|
|
16
|
+
type StrExpected,
|
|
17
|
+
type UnionStrExpected,
|
|
18
|
+
} from "./GetShortEventDoc.test";
|
|
13
19
|
import { mock_customEvents } from "./normal.test";
|
|
14
20
|
|
|
15
21
|
type Mock_CustomEventsDoc = GetCustomEventDoc<typeof mock_customEvents>;
|
|
@@ -20,6 +26,7 @@ export type Mock_CustomEventsDocExpected = {
|
|
|
20
26
|
nothing: undefined;
|
|
21
27
|
unionStr: UnionStrExpected;
|
|
22
28
|
union: ListExpected;
|
|
29
|
+
obj: ObjExpected;
|
|
23
30
|
bubbles: bubblesExpected;
|
|
24
31
|
capturePhase: CapturePhaseExpected;
|
|
25
32
|
bubbles_capturePhase: BubblesCapturePhaseExpected;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
4
|
+
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
3
5
|
import type { GetShortCustomEventsDoc } from "../GetCustomEventDoc";
|
|
4
6
|
import { mock_shortCustomEvents } from "./normal.test";
|
|
5
7
|
|
|
@@ -26,3 +28,9 @@ type ListResult = GetShortCustomEventsDoc<typeof mock_shortCustomEvents["union"]
|
|
|
26
28
|
export type ListExpected = string | 0 | 1 | 2 | null;
|
|
27
29
|
|
|
28
30
|
Checking<ListResult, ListExpected, Test.Pass>;
|
|
31
|
+
|
|
32
|
+
type ObjResult = GetShortCustomEventsDoc<typeof mock_shortCustomEvents["obj"]>;
|
|
33
|
+
|
|
34
|
+
export type ObjExpected = ReadonlyDeep<Mock_User>;
|
|
35
|
+
|
|
36
|
+
Checking<ObjResult, ObjExpected, Test.Pass>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
2
3
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
4
|
+
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
3
5
|
import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents } from "../CustomEventConstraint";
|
|
4
6
|
import type {
|
|
5
7
|
Bubbles,
|
|
@@ -19,6 +21,7 @@ export const mock_shortCustomEvents = {
|
|
|
19
21
|
null: null,
|
|
20
22
|
unionStr: String as DetailedType<"male" | "female">,
|
|
21
23
|
union: [String, Number as DetailedType<0 | 1 | 2>, null],
|
|
24
|
+
obj: Object as DetailedType<Mock_User>,
|
|
22
25
|
} satisfies Record<string, ShortCustomeEvents>;
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -68,6 +71,7 @@ type RootDoc = {
|
|
|
68
71
|
nothing: undefined;
|
|
69
72
|
unionStr: "male" | "female";
|
|
70
73
|
union: string | 0 | 1 | 2 | null;
|
|
74
|
+
obj: ReadonlyDeep<Mock_User>;
|
|
71
75
|
// 带options字段 通过联合类型加入。
|
|
72
76
|
bubbles: string | Bubbles;
|
|
73
77
|
capturePhase: null | Capture;
|
|
@@ -92,3 +96,22 @@ const rootDocNoFields = RootComponent()({});
|
|
|
92
96
|
|
|
93
97
|
// 3. 无customEvents字段时,Doc中无customEvents字段
|
|
94
98
|
Checking<typeof rootDocNoFields, {}, Test.Pass>;
|
|
99
|
+
|
|
100
|
+
// 4 实例中的对象数组都是readOnlyDeep类型,可以传递给自定义做参数
|
|
101
|
+
RootComponent()({
|
|
102
|
+
properties: {
|
|
103
|
+
obj: Object as DetailedType<Mock_User>,
|
|
104
|
+
},
|
|
105
|
+
data: {
|
|
106
|
+
obj1: {} as Mock_User,
|
|
107
|
+
_ddd: {} as Mock_User,
|
|
108
|
+
},
|
|
109
|
+
customEvents: mock_customEvents,
|
|
110
|
+
events: {
|
|
111
|
+
ddd() {
|
|
112
|
+
this.obj(this.data.obj!);
|
|
113
|
+
|
|
114
|
+
this.obj(this.data.obj1);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
|
+
import type { InnerFields } from "../../../types/InnerData";
|
|
2
3
|
|
|
3
4
|
export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
|
|
4
5
|
/**
|
|
@@ -9,9 +10,9 @@ export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey
|
|
|
9
10
|
& TSubData
|
|
10
11
|
& V.IllegalFieldValidator<
|
|
11
12
|
TSubData,
|
|
12
|
-
legalKeys |
|
|
13
|
+
legalKeys | InnerFields<TPrefix>,
|
|
13
14
|
0,
|
|
14
15
|
"",
|
|
15
|
-
"
|
|
16
|
+
"子组件无需此字段或与Inherit字段重复"
|
|
16
17
|
>;
|
|
17
18
|
};
|
|
@@ -27,7 +27,6 @@ SubComponent<{}, CompDoc>()({
|
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
//
|
|
31
30
|
SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
32
31
|
inherit: {
|
|
33
32
|
aaa_str: "wxml",
|
|
@@ -35,11 +34,22 @@ SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
|
35
34
|
aaa_obj: "wxml",
|
|
36
35
|
},
|
|
37
36
|
data: {
|
|
38
|
-
// 3
|
|
37
|
+
// 3 可写内部字段
|
|
39
38
|
_aaa_str: "str",
|
|
40
39
|
},
|
|
41
40
|
});
|
|
42
41
|
|
|
42
|
+
//
|
|
43
|
+
SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
44
|
+
inherit: {
|
|
45
|
+
aaa_str: "wxml",
|
|
46
|
+
},
|
|
47
|
+
data: {
|
|
48
|
+
// 4 可写isReady 特许字段 ExtraFields
|
|
49
|
+
aaa_isReady: false,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
43
53
|
SubComponent<{}, CompDoc>()({
|
|
44
54
|
data: {
|
|
45
55
|
aaa_str: "a",
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import type { V } from "hry-types";
|
|
2
|
+
|
|
3
|
+
export type SubInheritOption<TInherit extends object, legalKeys extends PropertyKey> = {
|
|
2
4
|
/**
|
|
3
5
|
* 继承来自根组件的数据(key)或'wxml',wxml表示数据来自`.wxml`文件(例如数据来自父元素循环wx:for的数据).
|
|
4
6
|
* inherit字段最终会在选项中删除,它的存在是为了ts开发时提供心智模型(类型检测),js开发好比注释功能.便于代码阅读。
|
|
5
7
|
* 带类型检测
|
|
6
8
|
*/
|
|
7
|
-
inherit?:
|
|
9
|
+
inherit?:
|
|
10
|
+
& TInherit
|
|
11
|
+
& V.IllegalFieldValidator<
|
|
12
|
+
TInherit,
|
|
13
|
+
legalKeys,
|
|
14
|
+
0,
|
|
15
|
+
""
|
|
16
|
+
>;
|
|
8
17
|
};
|
|
@@ -62,3 +62,15 @@ DefineComponent({
|
|
|
62
62
|
// @ts-expect-error 2 不能将类型“string”分配给类型“_SubComponentDoc”。
|
|
63
63
|
subComponents: [subDoc],
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
// 3 错误的key检查
|
|
67
|
+
|
|
68
|
+
SubComponent<Mock_RootDoc, Mock_CompDoc>()({
|
|
69
|
+
inherit: {
|
|
70
|
+
aaa_num: "required_num",
|
|
71
|
+
// @ts-expect-error 3.1 不存在于组件中的key给错误提示
|
|
72
|
+
xxx: "",
|
|
73
|
+
// @ts-expect-error 3.2 不存在于组件中的key给错误提示
|
|
74
|
+
aaa_xxx: "",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
|
+
import type { InnerFields } from "../../../types/InnerData";
|
|
2
3
|
|
|
3
|
-
export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey> = {
|
|
4
|
+
export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
|
|
4
5
|
/**
|
|
5
6
|
* 全局响应式数据字段,全局store对应数据变化实例对应数据自动setData。
|
|
6
7
|
* 约束为组件properties字段去除inherit和data的剩余字段和内部字段
|
|
@@ -19,8 +20,8 @@ export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyK
|
|
|
19
20
|
& TSubStore
|
|
20
21
|
& V.IllegalFieldValidator<
|
|
21
22
|
TSubStore,
|
|
22
|
-
legalKeys,
|
|
23
|
-
|
|
23
|
+
// legalKeys,
|
|
24
|
+
legalKeys | InnerFields<TPrefix>,
|
|
24
25
|
0,
|
|
25
26
|
"",
|
|
26
27
|
"与inherit和data字段重复或前缀错误"
|
|
@@ -25,6 +25,7 @@ SubComponent<{
|
|
|
25
25
|
},
|
|
26
26
|
data: {
|
|
27
27
|
aaa_num: 20,
|
|
28
|
+
aaa_isReady: false,
|
|
28
29
|
},
|
|
29
30
|
store: {
|
|
30
31
|
// @ts-expect-error 1 与 inherit 字段重复
|
|
@@ -33,5 +34,9 @@ SubComponent<{
|
|
|
33
34
|
aaa_num: () => user.age,
|
|
34
35
|
// @ts-expect-error 3 超出约束字段
|
|
35
36
|
num: () => user.age,
|
|
37
|
+
// @ts-expect-error 4 于data字段重复
|
|
38
|
+
aaa_isReady() {
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
36
41
|
},
|
|
37
42
|
});
|
|
@@ -16,20 +16,22 @@ type DocA = ComponentDoc<{
|
|
|
16
16
|
|
|
17
17
|
SubComponent<{}, DocA>()({
|
|
18
18
|
store: {
|
|
19
|
+
// 1 可写组件字段
|
|
19
20
|
aaa_str: () => user.name,
|
|
20
|
-
|
|
21
21
|
aaa_num: () => user.age,
|
|
22
|
-
// 内部字段
|
|
23
|
-
// _aaa_ddd: () => user.age,
|
|
24
22
|
},
|
|
25
23
|
});
|
|
26
24
|
|
|
27
25
|
SubComponent<{}, DocA, "a">()({
|
|
28
26
|
store: {
|
|
29
|
-
|
|
27
|
+
// 2 可写内部字段
|
|
28
|
+
_aaaA_xxxxxx: () => user.age,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
32
|
+
SubComponent<{}, DocA, "a">()({
|
|
33
|
+
store: {
|
|
34
|
+
// 3 可写特许字段
|
|
35
|
+
aaaA_isReady: () => false,
|
|
34
36
|
},
|
|
35
37
|
});
|
|
@@ -6,6 +6,8 @@ import type { ReplacePrefix } from "../../types/ReplacePrefix";
|
|
|
6
6
|
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
|
|
7
7
|
|
|
8
8
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
9
|
+
import type { Extra } from "../../types/Extra";
|
|
10
|
+
import type { InnerFields } from "../../types/InnerData";
|
|
9
11
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
10
12
|
import type { Replace } from "../../types/Replace";
|
|
11
13
|
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
@@ -56,15 +58,16 @@ type Options<
|
|
|
56
58
|
SubEventsDoc extends object,
|
|
57
59
|
SubMethodsDoc extends object,
|
|
58
60
|
> =
|
|
59
|
-
& SubInheritOption<TInherit>
|
|
61
|
+
& SubInheritOption<TInherit, keyof CurrentCompDoc["properties"]>
|
|
60
62
|
& SubDataOption<
|
|
61
63
|
TSubData,
|
|
62
|
-
Exclude<keyof CurrentCompDoc["properties"]
|
|
64
|
+
Exclude<keyof CurrentCompDoc["properties"] | keyof Extra<Prefix>, (keyof InheritDoc)>,
|
|
63
65
|
Prefix
|
|
64
66
|
>
|
|
65
67
|
& SubStoreOption<
|
|
66
68
|
TSubStore,
|
|
67
|
-
Exclude<keyof CurrentCompDoc["properties"]
|
|
69
|
+
Exclude<keyof CurrentCompDoc["properties"] | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>,
|
|
70
|
+
Prefix
|
|
68
71
|
>
|
|
69
72
|
& SubComputedOption<
|
|
70
73
|
TSubComputed,
|
|
@@ -126,12 +129,21 @@ type SubComponentConstructor<
|
|
|
126
129
|
> = {
|
|
127
130
|
<
|
|
128
131
|
TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>,
|
|
129
|
-
TSubData extends SubDataConstraint<
|
|
130
|
-
|
|
132
|
+
TSubData extends SubDataConstraint<
|
|
133
|
+
& Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>
|
|
134
|
+
& Extra<CurrentPrefix> // 加入特许字段 isReady
|
|
135
|
+
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
136
|
+
>,
|
|
137
|
+
TSubStore extends SubStoreConstraint<
|
|
138
|
+
& Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)>
|
|
139
|
+
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
140
|
+
>,
|
|
131
141
|
TEvents extends SubEventsConstraint<CurrentCompDoc>,
|
|
132
142
|
// 加默认值计算字段无提示且需要手写返回类型,不加watch无法对computed监控
|
|
133
143
|
TSubComputed extends SubComputedConstraint<
|
|
134
|
-
Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
|
|
144
|
+
& Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
|
|
145
|
+
& Extra<CurrentPrefix> // 加入特许字段 isReady
|
|
146
|
+
& Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
|
|
135
147
|
> = {},
|
|
136
148
|
TSubMethods extends SubMethodsConstraint = {},
|
|
137
149
|
InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Extra<Prefix extends string> = Record<`${Prefix}_isReady`, boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type InnerFields<Prefix extends string> = `_${Prefix}_${string}`;
|