annil 1.5.15 → 1.6.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 +15 -0
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js +3 -2
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.d.ts +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js +2 -13
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.js +3 -2
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/index.d.ts +1 -0
- package/dist/api/DefineComponent/assignOptions/index.js +8 -0
- package/dist/api/DefineComponent/assignOptions/index.js.map +1 -1
- package/dist/api/RootComponent/Computed/ComputedOption.d.ts +2 -2
- package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +2 -2
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +1 -2
- package/dist/api/RootComponent/Data/DataOption.d.ts +2 -2
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +5 -2
- package/dist/api/RootComponent/Methods/MethodsOption.d.ts +2 -2
- package/dist/api/RootComponent/Properties/PropertiesOption.d.ts +2 -2
- package/dist/api/RootComponent/Store/StoreOption.d.ts +2 -2
- package/dist/api/RootComponent/index.d.ts +4 -2
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubComputed/SubComputedOption.d.ts +2 -2
- package/dist/api/SubComponent/SubData/SubDataOption.d.ts +3 -4
- package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +2 -2
- package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +2 -2
- package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +2 -2
- package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +3 -4
- package/dist/api/SubComponent/index.d.ts +3 -4
- package/package.json +4 -6
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +10 -0
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts +3 -3
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts +3 -25
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.ts +3 -2
- package/src/api/DefineComponent/assignOptions/index.ts +14 -1
- package/src/api/RootComponent/Computed/ComputedOption.ts +6 -1
- package/src/api/RootComponent/Computed/GetComputedDoc.ts +3 -1
- package/src/api/RootComponent/Computed/test/error.test.ts +2 -2
- package/src/api/RootComponent/Computed/test/normal.test.ts +13 -11
- package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +3 -3
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +1 -3
- package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +1 -2
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +1 -2
- package/src/api/RootComponent/Data/DataOption.ts +2 -2
- package/src/api/RootComponent/Data/test/normal.test.ts +2 -0
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -1
- package/src/api/RootComponent/Instance/test/cloneData/error.test.ts +31 -0
- package/src/api/RootComponent/Instance/test/cloneData/normal.test.ts +53 -0
- package/src/api/RootComponent/Methods/MethodsOption.ts +2 -2
- package/src/api/RootComponent/Properties/PropertiesOption.ts +2 -2
- package/src/api/RootComponent/Properties/test/normalRequired.test.ts +3 -3
- package/src/api/RootComponent/Store/StoreOption.ts +2 -2
- package/src/api/RootComponent/index.ts +6 -2
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +2 -2
- package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -15
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +0 -13
- package/src/api/SubComponent/SubData/SubDataOption.ts +4 -5
- package/src/api/SubComponent/SubData/test/normal.test.ts +0 -11
- package/src/api/SubComponent/SubEvents/SubEventsOptions.ts +2 -2
- package/src/api/SubComponent/SubInherit/SubInheritOption.ts +2 -2
- package/src/api/SubComponent/SubInstance/test/cloneData/error.test.ts +22 -0
- package/src/api/SubComponent/SubInstance/test/cloneData/normal.test.ts +73 -0
- package/src/api/SubComponent/SubMethods/SubMethodsOption.ts +2 -2
- package/src/api/SubComponent/SubStore/SubStoreOption.ts +4 -5
- package/src/api/SubComponent/SubStore/test/error.test.ts +0 -5
- package/src/api/SubComponent/SubStore/test/normal.test.ts +1 -8
- package/src/api/SubComponent/index.ts +12 -12
- package/src/types/Extra.ts +1 -1
- package/dist/types/Extra.d.ts +0 -1
- package/dist/types/Extra.js +0 -2
- package/dist/types/Extra.js.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/_api";
|
|
2
2
|
import { BBeforeCreate } from "../../../behaviors/BbeforeCreated";
|
|
3
|
-
|
|
4
3
|
import type { Assign } from "../../../types/Assign";
|
|
5
4
|
import type { WMComponent } from "../../../types/OfficialTypeAlias";
|
|
6
5
|
import { deepClone } from "../../../utils/deepClone";
|
|
@@ -34,6 +33,7 @@ import { initStore } from "./initStore";
|
|
|
34
33
|
type InstanceInnerFields = {
|
|
35
34
|
data: OptionsInnerFields["data"];
|
|
36
35
|
disposer: Record<string, Func>;
|
|
36
|
+
cloneData: OptionsInnerFields["data"];
|
|
37
37
|
} & OptionsInnerFields["methods"];
|
|
38
38
|
|
|
39
39
|
export type Instance =
|
|
@@ -101,6 +101,13 @@ export function isPageCheck(isPage: boolean | undefined) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function addCloneDataToInstance(this: Instance) {
|
|
105
|
+
this.cloneData = new Proxy(this.data, {
|
|
106
|
+
get: <T extends object>(target: T, key: keyof T) => {
|
|
107
|
+
return deepClone(target)[key];
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
104
111
|
/**
|
|
105
112
|
* 原生Component会对传入的对象字段匹配的properties字段setData赋值。不符合字段或Page时不会赋值。
|
|
106
113
|
* 此函数为给实例setData赋值,默认传递值与properties相符(ts类型安全)。
|
|
@@ -439,6 +446,12 @@ export function assignOptions(
|
|
|
439
446
|
[isPageCheck(rootComponentOption?.isPage)],
|
|
440
447
|
);
|
|
441
448
|
|
|
449
|
+
hijack(
|
|
450
|
+
finalOptionsForComponent.lifetimes!,
|
|
451
|
+
"created",
|
|
452
|
+
[addCloneDataToInstance],
|
|
453
|
+
);
|
|
454
|
+
|
|
442
455
|
// 页面时删除预设的虚拟组件字段
|
|
443
456
|
finalOptionsForComponent.isPage
|
|
444
457
|
&& finalOptionsForComponent.options && Reflect.deleteProperty(finalOptionsForComponent.options, "virtualHost");
|
|
@@ -2,7 +2,11 @@ import type { DuplicateFieldValidator } from "hry-types/src/Generic/DuplicateFie
|
|
|
2
2
|
|
|
3
3
|
import type { ComputedConstraint } from "./ComputedConstraint";
|
|
4
4
|
|
|
5
|
-
export type ComputedOption<
|
|
5
|
+
export type ComputedOption<
|
|
6
|
+
TComputed extends ComputedConstraint,
|
|
7
|
+
CompareKeys extends PropertyKey,
|
|
8
|
+
Instance extends object,
|
|
9
|
+
> = {
|
|
6
10
|
/**
|
|
7
11
|
* computed字段, [类型约束ComputedConstraint](ComputedConstraint.ts)
|
|
8
12
|
* @remarks
|
|
@@ -28,5 +32,6 @@ export type ComputedOption<TComputed extends ComputedConstraint, CompareKeys ext
|
|
|
28
32
|
*/
|
|
29
33
|
computed?:
|
|
30
34
|
& TComputed
|
|
35
|
+
& ThisType<Instance>
|
|
31
36
|
& DuplicateFieldValidator<TComputed, CompareKeys>;
|
|
32
37
|
};
|
|
@@ -5,4 +5,6 @@ import type { ComputedConstraint } from "./ComputedConstraint";
|
|
|
5
5
|
* @param T - ComputedConstraint
|
|
6
6
|
* @returns object
|
|
7
7
|
*/
|
|
8
|
-
export type GetComputedDoc<TComputed extends ComputedConstraint> = {
|
|
8
|
+
export type GetComputedDoc<TComputed extends ComputedConstraint> = {
|
|
9
|
+
[k in keyof TComputed]: ReturnType<TComputed[k]>;
|
|
10
|
+
};
|
|
@@ -10,6 +10,7 @@ const RootDoc = RootComponent()({
|
|
|
10
10
|
},
|
|
11
11
|
data: {
|
|
12
12
|
lastName: "lastName",
|
|
13
|
+
mock_User: {} as Mock_User,
|
|
13
14
|
},
|
|
14
15
|
store: {
|
|
15
16
|
prefix: () => "hry-", // 模拟而已
|
|
@@ -30,17 +31,18 @@ const RootDoc = RootComponent()({
|
|
|
30
31
|
// 3 this.data 类型是深度只读的
|
|
31
32
|
Checking<
|
|
32
33
|
typeof this.data,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
{
|
|
35
|
+
firstName: string;
|
|
36
|
+
lastName: string;
|
|
37
|
+
mock_User: Mock_User;
|
|
38
|
+
fullName: string;
|
|
39
|
+
user: Mock_User;
|
|
40
|
+
prefix: string;
|
|
41
|
+
id_fullName: string;
|
|
42
|
+
readOnly: "str";
|
|
43
|
+
injectStr: string;
|
|
44
|
+
injectTheme: "light" | "dark" | undefined;
|
|
45
|
+
},
|
|
44
46
|
Test.Pass
|
|
45
47
|
>;
|
|
46
48
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
import type { CustomEventConstraint } from "./CustomEventConstraint";
|
|
3
3
|
|
|
4
4
|
export type CustomEventsOption<
|
|
@@ -36,6 +36,6 @@ export type CustomEventsOption<
|
|
|
36
36
|
*/
|
|
37
37
|
customEvents?:
|
|
38
38
|
& TCustomEvents
|
|
39
|
-
&
|
|
40
|
-
&
|
|
39
|
+
& G.IllegalFieldValidator<TCustomEvents, "bubbles" | "composed" | "capturePhase", 1, "options">
|
|
40
|
+
& G.DuplicateFieldValidator<TCustomEvents, EventsKeys, "与events字段重复">;
|
|
41
41
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
2
1
|
import type { DetailedType } from "../../../types/DetailedType";
|
|
3
2
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
4
3
|
import type {
|
|
@@ -9,8 +8,7 @@ import type {
|
|
|
9
8
|
} from "./CustomEventConstraint";
|
|
10
9
|
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
11
10
|
|
|
12
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType
|
|
13
|
-
? ReadonlyDeep<InferDetailedType<T>>
|
|
11
|
+
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T>
|
|
14
12
|
: T extends null ? null
|
|
15
13
|
: T extends undefined ? undefined
|
|
16
14
|
: T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
4
3
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
5
4
|
import type { GetShortCustomEventsDoc } from "../GetCustomEventDoc";
|
|
6
5
|
import { mock_shortCustomEvents } from "./normal.test";
|
|
@@ -31,6 +30,6 @@ Checking<ListResult, ListExpected, Test.Pass>;
|
|
|
31
30
|
|
|
32
31
|
type ObjResult = GetShortCustomEventsDoc<typeof mock_shortCustomEvents["obj"]>;
|
|
33
32
|
|
|
34
|
-
export type ObjExpected =
|
|
33
|
+
export type ObjExpected = Mock_User;
|
|
35
34
|
|
|
36
35
|
Checking<ObjResult, ObjExpected, Test.Pass>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
3
2
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
4
3
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
5
4
|
import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents } from "../CustomEventConstraint";
|
|
@@ -71,7 +70,7 @@ type RootDoc = {
|
|
|
71
70
|
nothing: undefined;
|
|
72
71
|
unionStr: "male" | "female";
|
|
73
72
|
union: string | 0 | 1 | 2 | null;
|
|
74
|
-
obj:
|
|
73
|
+
obj: Mock_User;
|
|
75
74
|
// 带options字段 通过联合类型加入。
|
|
76
75
|
bubbles: string | Bubbles;
|
|
77
76
|
capturePhase: null | Capture;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
|
|
3
3
|
export type DataOption<TData extends object, PropertiesKeys extends PropertyKey> = {
|
|
4
4
|
/**
|
|
@@ -17,5 +17,5 @@ export type DataOption<TData extends object, PropertiesKeys extends PropertyKey>
|
|
|
17
17
|
*/
|
|
18
18
|
data?:
|
|
19
19
|
& TData
|
|
20
|
-
&
|
|
20
|
+
& G.DuplicateFieldValidator<TData, PropertiesKeys, "与properties字段重复">;
|
|
21
21
|
};
|
|
@@ -4,6 +4,7 @@ import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersecti
|
|
|
4
4
|
import type { IReactionDisposer } from "mobx";
|
|
5
5
|
|
|
6
6
|
import type { Assign } from "../../../types/Assign";
|
|
7
|
+
import type { ComputeObject } from "../../../types/ComputeObj";
|
|
7
8
|
import type { WMComponentInstance, WMInstanceMethods, WMPageInstance } from "../../../types/OfficialTypeAlias";
|
|
8
9
|
import type { IInjectData, IInjectMethods } from "../../InstanceInject/instanceConfig";
|
|
9
10
|
import type { CustomEventMethods } from "./CustomEventMethods";
|
|
@@ -15,6 +16,7 @@ export type RootComponentInstance<
|
|
|
15
16
|
AllData extends object,
|
|
16
17
|
CustomEventsDoc extends object,
|
|
17
18
|
StoreDoc extends object,
|
|
19
|
+
instanceData = ComputeObject<Assign<IInjectData, ComputeIntersection<AllData>>>,
|
|
18
20
|
> =
|
|
19
21
|
// 官方实例属性is options dataset等
|
|
20
22
|
& IfExtends<false, TIsPage, WMComponentInstance, WMPageInstance>
|
|
@@ -26,7 +28,8 @@ export type RootComponentInstance<
|
|
|
26
28
|
disposer: { [k in keyof StoreDoc]: IReactionDisposer };
|
|
27
29
|
}>
|
|
28
30
|
& Assign<IInjectMethods, TMethods & CustomEventMethods<CustomEventsDoc>>
|
|
29
|
-
& { data: ReadonlyDeep<
|
|
31
|
+
& { data: ReadonlyDeep<instanceData> }
|
|
32
|
+
& { cloneData: ComputeObject<Assign<IInjectData, ComputeIntersection<AllData>>> };
|
|
30
33
|
|
|
31
34
|
export type ComponentInstance = RootComponentInstance<false, {}, {}, {}, {}, {}>;
|
|
32
35
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DetailedType } from "../../../../..";
|
|
2
|
+
import { RootComponent } from "../../..";
|
|
3
|
+
|
|
4
|
+
interface User {
|
|
5
|
+
readonly id: number;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
slected: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
RootComponent()({
|
|
11
|
+
properties: {
|
|
12
|
+
num: Number,
|
|
13
|
+
user: Object as DetailedType<User>,
|
|
14
|
+
},
|
|
15
|
+
data: {
|
|
16
|
+
str: "123",
|
|
17
|
+
arr: [{}] as User[],
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
methods: {
|
|
21
|
+
M1() {
|
|
22
|
+
const cloneData = this.cloneData;
|
|
23
|
+
|
|
24
|
+
// @ts-expect-error 尽管cloneData去除了readonly,user.id属性依然是readonly
|
|
25
|
+
cloneData.user!.id = 1;
|
|
26
|
+
|
|
27
|
+
// @ts-expect-error arr[0].name属性依然是readonly
|
|
28
|
+
cloneData.arr[0].name = "zhao";
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Checking, type Test } from "hry-types";
|
|
2
|
+
import type { _ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
+
import type { DetailedType } from "../../../../..";
|
|
4
|
+
import { RootComponent } from "../../..";
|
|
5
|
+
|
|
6
|
+
interface User {
|
|
7
|
+
readonly id: number;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
slected: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
RootComponent()({
|
|
13
|
+
properties: {
|
|
14
|
+
num: Number,
|
|
15
|
+
obj: Object as DetailedType<User>,
|
|
16
|
+
},
|
|
17
|
+
data: {
|
|
18
|
+
str: "123",
|
|
19
|
+
arr: [{}] as User[],
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
methods: {
|
|
23
|
+
M1() {
|
|
24
|
+
Checking<
|
|
25
|
+
typeof this.data,
|
|
26
|
+
_ReadonlyDeep<
|
|
27
|
+
{
|
|
28
|
+
injectTheme: "dark" | "light" | undefined;
|
|
29
|
+
injectStr: string;
|
|
30
|
+
str: string;
|
|
31
|
+
arr: User[];
|
|
32
|
+
num: number;
|
|
33
|
+
obj: User | null;
|
|
34
|
+
}
|
|
35
|
+
>,
|
|
36
|
+
Test.Pass
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
Checking<
|
|
40
|
+
typeof this.cloneData,
|
|
41
|
+
{
|
|
42
|
+
injectTheme: "dark" | "light" | undefined;
|
|
43
|
+
injectStr: string;
|
|
44
|
+
str: string;
|
|
45
|
+
arr: User[];
|
|
46
|
+
num: number;
|
|
47
|
+
obj: User | null;
|
|
48
|
+
},
|
|
49
|
+
Test.Pass
|
|
50
|
+
>;
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
|
|
3
3
|
import type { MethodsConstraint } from "./MethodsConstraint";
|
|
4
4
|
|
|
@@ -11,5 +11,5 @@ export type MethodsOption<
|
|
|
11
11
|
*/
|
|
12
12
|
methods?:
|
|
13
13
|
& TMethods
|
|
14
|
-
&
|
|
14
|
+
& G.DuplicateFieldValidator<TMethods, DuplicateField>;
|
|
15
15
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
import type { Validators } from "../../../types/Validators";
|
|
3
3
|
import type { PropertiesConstraint } from "./PropertiesConstraint";
|
|
4
4
|
import type { PropertiesValueValidator } from "./PropertiesValueValidator";
|
|
@@ -21,6 +21,6 @@ export type PropertiesOption<
|
|
|
21
21
|
& Validators<[
|
|
22
22
|
PropertiesValueValidator<TProperties>,
|
|
23
23
|
// 放在最后一个,正常返回不是unknown 而是Record<string,unknown>
|
|
24
|
-
|
|
24
|
+
G.IllegalFieldValidator<TProperties, "value" | "type" | "optionalTypes", 1>,
|
|
25
25
|
]>;
|
|
26
26
|
};
|
|
@@ -9,10 +9,10 @@ import type { RequiredSingle, RequiredType, RequiredUnion } from "../PropertiesC
|
|
|
9
9
|
/**
|
|
10
10
|
* 共用测试对象类型
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
id: string;
|
|
12
|
+
export interface Mock_User {
|
|
13
|
+
readonly id: string;
|
|
14
14
|
age?: number;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* 共用测试对象类型
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
3
3
|
|
|
4
4
|
export type StoreOption<TStore extends StoreConstraint, TDuplicateKeys extends PropertyKey> = {
|
|
@@ -16,5 +16,5 @@ export type StoreOption<TStore extends StoreConstraint, TDuplicateKeys extends P
|
|
|
16
16
|
*/
|
|
17
17
|
store?:
|
|
18
18
|
& TStore
|
|
19
|
-
&
|
|
19
|
+
& G.DuplicateFieldValidator<TStore, TDuplicateKeys, "字段重复">;
|
|
20
20
|
};
|
|
@@ -5,7 +5,7 @@ import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
|
5
5
|
import type { ComputeObject } from "../../types/ComputeObj";
|
|
6
6
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
7
7
|
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
|
|
8
|
-
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
8
|
+
import type { IInjectData, IInjectStore } from "../InstanceInject/instanceConfig";
|
|
9
9
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
10
10
|
import type { ComputedOption } from "./Computed/ComputedOption";
|
|
11
11
|
import type { GetComputedDoc } from "./Computed/GetComputedDoc";
|
|
@@ -55,7 +55,11 @@ type RootComponentOptions<
|
|
|
55
55
|
& CustomEventsOption<TCustomEvents, keyof EventsDoc>
|
|
56
56
|
& DataOption<TData, keyof PropertiesDoc>
|
|
57
57
|
& StoreOption<TStore, keyof (PropertiesDoc & DataDoc)>
|
|
58
|
-
& ComputedOption<
|
|
58
|
+
& ComputedOption<
|
|
59
|
+
TComputed,
|
|
60
|
+
keyof (PropertiesDoc & DataDoc & StoreDoc),
|
|
61
|
+
{ data: ComputeObject<DataDoc & Required<PropertiesDoc> & StoreDoc & ComputedDoc & IInjectData> }
|
|
62
|
+
>
|
|
59
63
|
& PageLifetimesOption<TIsPage, PropertiesDoc>
|
|
60
64
|
& LifetimesOption
|
|
61
65
|
& WatchOption<
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
export type SubComputedOption<
|
|
3
3
|
TComputed extends object,
|
|
4
4
|
legal extends PropertyKey,
|
|
5
5
|
> = {
|
|
6
6
|
computed?:
|
|
7
7
|
& TComputed
|
|
8
|
-
&
|
|
8
|
+
& G.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
9
9
|
};
|
|
@@ -22,7 +22,7 @@ type OnlyPropsCompDoc = ComponentDoc<{
|
|
|
22
22
|
};
|
|
23
23
|
}>;
|
|
24
24
|
|
|
25
|
-
// 2 去除inhrit和data
|
|
25
|
+
// 2 去除inhrit和data字段后无组件字段约束时,只可写内部字段
|
|
26
26
|
SubComponent<{}, OnlyPropsCompDoc>()({
|
|
27
27
|
inherit: {
|
|
28
28
|
aaa_str: "wxml",
|
|
@@ -31,8 +31,9 @@ SubComponent<{}, OnlyPropsCompDoc>()({
|
|
|
31
31
|
aaa_num: 123,
|
|
32
32
|
},
|
|
33
33
|
computed: {
|
|
34
|
-
// @ts-expect-error ⚠️"重复或无效的字段"⚠️
|
|
35
34
|
_aaa_xxx() {},
|
|
35
|
+
// @ts-expect-error 只可写内部字段
|
|
36
|
+
aaa_yyy() {},
|
|
36
37
|
},
|
|
37
38
|
});
|
|
38
39
|
|
|
@@ -48,16 +49,3 @@ SubComponent<{}, OnlyPropsCompDoc>()({
|
|
|
48
49
|
},
|
|
49
50
|
},
|
|
50
51
|
});
|
|
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,18 +140,5 @@ 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
|
-
},
|
|
156
143
|
},
|
|
157
144
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { InnerFields } from "../../../types/InnerData";
|
|
1
|
+
import type { G } from "hry-types";
|
|
3
2
|
|
|
4
|
-
export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey
|
|
3
|
+
export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey> = {
|
|
5
4
|
/**
|
|
6
5
|
* 可写子组件所需数据和内部公共数据
|
|
7
6
|
* 非法字段检测和与Inherit字段的重复检测
|
|
8
7
|
*/
|
|
9
8
|
data?:
|
|
10
9
|
& TSubData
|
|
11
|
-
&
|
|
10
|
+
& G.IllegalFieldValidator<
|
|
12
11
|
TSubData,
|
|
13
|
-
legalKeys
|
|
12
|
+
legalKeys,
|
|
14
13
|
0,
|
|
15
14
|
"",
|
|
16
15
|
"子组件无需此字段或与Inherit字段重复"
|
|
@@ -39,17 +39,6 @@ SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
|
39
39
|
},
|
|
40
40
|
});
|
|
41
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
|
-
|
|
53
42
|
SubComponent<{}, CompDoc>()({
|
|
54
43
|
data: {
|
|
55
44
|
aaa_str: "a",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
|
|
3
3
|
export type SubEventsOption<TSubEvents, SubEventsDoc extends object, legalKeys extends PropertyKey> = {
|
|
4
4
|
/**
|
|
@@ -8,5 +8,5 @@ export type SubEventsOption<TSubEvents, SubEventsDoc extends object, legalKeys e
|
|
|
8
8
|
*/
|
|
9
9
|
events?:
|
|
10
10
|
& TSubEvents
|
|
11
|
-
&
|
|
11
|
+
& G.IllegalFieldValidator<SubEventsDoc, legalKeys>;
|
|
12
12
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
|
|
3
3
|
export type SubInheritOption<TInherit extends object, legalKeys extends PropertyKey> = {
|
|
4
4
|
/**
|
|
@@ -8,7 +8,7 @@ export type SubInheritOption<TInherit extends object, legalKeys extends Property
|
|
|
8
8
|
*/
|
|
9
9
|
inherit?:
|
|
10
10
|
& TInherit
|
|
11
|
-
&
|
|
11
|
+
& G.IllegalFieldValidator<
|
|
12
12
|
TInherit,
|
|
13
13
|
legalKeys,
|
|
14
14
|
0,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { View } from "../../../../../thirdLib/wm";
|
|
2
|
+
import type { RootComponentDoc } from "../../../../RootComponent/RootComponentDoc";
|
|
3
|
+
import { SubComponent } from "../../..";
|
|
4
|
+
|
|
5
|
+
type RootDoc = RootComponentDoc<{
|
|
6
|
+
events: {
|
|
7
|
+
RootE1: () => string;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
// 实例中只存在RootDoc和自身的methods字段
|
|
12
|
+
SubComponent<RootDoc, View>()({
|
|
13
|
+
lifetimes: {
|
|
14
|
+
created() {
|
|
15
|
+
// @ts-expect-error 不存在的方法 (Root事件方法不可调用)
|
|
16
|
+
this.RootE1;
|
|
17
|
+
|
|
18
|
+
// @ts-expect-error 不存在的方法
|
|
19
|
+
this.otherMethods();
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Checking, type Test } from "hry-types";
|
|
2
|
+
import type { ComponentDoc } from "../../../../DefineComponent/ReturnType/ComponentDoc";
|
|
3
|
+
import type { Mock_User } from "../../../../RootComponent/Properties/test/normalRequired.test";
|
|
4
|
+
import type { RootComponentDoc } from "../../../../RootComponent/RootComponentDoc";
|
|
5
|
+
import { SubComponent } from "../../..";
|
|
6
|
+
|
|
7
|
+
type RootDoc = RootComponentDoc<{
|
|
8
|
+
properties: {
|
|
9
|
+
Pstr: string;
|
|
10
|
+
Pobj: Mock_User | null;
|
|
11
|
+
PoptionalObj?: Mock_User;
|
|
12
|
+
};
|
|
13
|
+
data: {
|
|
14
|
+
Dnum: number;
|
|
15
|
+
};
|
|
16
|
+
computed: {
|
|
17
|
+
Cnum: number;
|
|
18
|
+
};
|
|
19
|
+
methods: {
|
|
20
|
+
RootM: () => number;
|
|
21
|
+
};
|
|
22
|
+
customEvents: {
|
|
23
|
+
RootCus: string;
|
|
24
|
+
};
|
|
25
|
+
events: {
|
|
26
|
+
RootE1: () => string;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
type CompDoc = ComponentDoc<{
|
|
31
|
+
properties: {
|
|
32
|
+
aaa_str: string;
|
|
33
|
+
};
|
|
34
|
+
customEvents: {
|
|
35
|
+
aaa_num: number;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
|
|
39
|
+
SubComponent<RootDoc, CompDoc>()({
|
|
40
|
+
data: {
|
|
41
|
+
aaa_str: "str",
|
|
42
|
+
_aaa_num: 123,
|
|
43
|
+
},
|
|
44
|
+
computed: {
|
|
45
|
+
_aaa_isReady() {
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
lifetimes: {
|
|
51
|
+
created() {
|
|
52
|
+
Checking<
|
|
53
|
+
typeof this.cloneData,
|
|
54
|
+
{
|
|
55
|
+
// inheritData
|
|
56
|
+
injectTheme: "dark" | "light" | undefined;
|
|
57
|
+
injectStr: string;
|
|
58
|
+
// RootData
|
|
59
|
+
Pstr: string;
|
|
60
|
+
Pobj: Mock_User | null;
|
|
61
|
+
PoptionalObj: Mock_User;
|
|
62
|
+
Dnum: number;
|
|
63
|
+
Cnum: number;
|
|
64
|
+
// 自身Data类型与CompDoc类型相同
|
|
65
|
+
aaa_str: string;
|
|
66
|
+
_aaa_isReady: boolean;
|
|
67
|
+
_aaa_num: number;
|
|
68
|
+
},
|
|
69
|
+
Test.Pass
|
|
70
|
+
>;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { G } from "hry-types";
|
|
2
2
|
import type { PrefixValidator } from "hry-types/src/Generic/PrefixValidator";
|
|
3
3
|
import type { SubMethodsConstraint } from "./SubMethodsConstraint";
|
|
4
4
|
|
|
@@ -13,5 +13,5 @@ export type SubMethodsOption<
|
|
|
13
13
|
methods?:
|
|
14
14
|
& TSubMethods
|
|
15
15
|
& PrefixValidator<TSubMethods, TPrefix>
|
|
16
|
-
&
|
|
16
|
+
& G.DuplicateFieldValidator<TSubMethods, ExcludedKeys>;
|
|
17
17
|
};
|