annil 1.4.0 → 1.5.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 +19 -0
- package/README.md +4 -4
- package/dist/api/DefineComponent/collectOptionsForComponent.js +30 -11
- package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
- package/dist/api/DefineComponent/index.js.map +1 -1
- package/dist/api/InstanceInject/inject.d.ts +18 -0
- package/dist/api/InstanceInject/inject.js +20 -0
- package/dist/api/InstanceInject/inject.js.map +1 -0
- package/dist/api/InstanceInject/instanceConfig.d.ts +23 -0
- package/dist/api/InstanceInject/instanceConfig.js +13 -0
- package/dist/api/InstanceInject/instanceConfig.js.map +1 -0
- package/dist/api/InstanceInject/test/normal.test.d.ts +1 -0
- package/dist/api/InstanceInject/test/normal.test.js +30 -0
- package/dist/api/InstanceInject/test/normal.test.js.map +1 -0
- package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
- package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/setData/error.test.js +0 -8
- package/dist/api/RootComponent/Instance/test/setData/error.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/setData/normal.test.js +0 -1
- package/dist/api/RootComponent/Instance/test/setData/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +1 -1
- package/dist/api/RootComponent/Lifetimes/test/normal.test.js +2 -0
- package/dist/api/RootComponent/Lifetimes/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalRequired.test.js.map +1 -1
- package/dist/api/RootComponent/Watch/test/WtachInject.test.d.ts +1 -0
- package/dist/api/RootComponent/Watch/test/WtachInject.test.js +15 -0
- package/dist/api/RootComponent/Watch/test/WtachInject.test.js.map +1 -0
- package/dist/api/RootComponent/index.d.ts +2 -1
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/SubWatchOption.d.ts +1 -2
- package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/types.d.ts +0 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Assign.d.ts +1 -0
- package/dist/types/Assign.js +2 -0
- package/dist/types/Assign.js.map +1 -0
- package/dist/types/OfficialTypeAlias.d.ts +1 -1
- package/package.json +2 -4
- package/src/api/DefineComponent/collectOptionsForComponent.ts +47 -11
- package/src/api/DefineComponent/index.ts +1 -0
- package/src/api/InstanceInject/inject.ts +34 -0
- package/src/api/InstanceInject/instanceConfig.ts +39 -0
- package/src/api/InstanceInject/test/normal.test.ts +40 -0
- package/src/api/RootComponent/Computed/test/normal.test.ts +14 -11
- package/src/api/RootComponent/Data/test/normal.test.ts +4 -3
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -5
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +6 -1
- package/src/api/RootComponent/Instance/test/setData/error.test.ts +0 -10
- package/src/api/RootComponent/Instance/test/setData/normal.test.ts +0 -3
- package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +1 -1
- package/src/api/RootComponent/Lifetimes/test/normal.test.ts +3 -0
- package/src/api/RootComponent/Properties/test/normalEmpty.test.ts +4 -2
- package/src/api/RootComponent/Properties/test/normalOptional.test.ts +11 -8
- package/src/api/RootComponent/Properties/test/normalRequired.test.ts +2 -1
- package/src/api/RootComponent/Watch/test/WtachInject.test.ts +20 -0
- package/src/api/RootComponent/index.ts +2 -0
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +27 -22
- package/src/api/SubComponent/SubData/test/normal.test.ts +9 -6
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +14 -11
- package/src/api/SubComponent/SubWatch/SubWatchOption.ts +1 -2
- package/src/behaviors/BComputedAndWatch/data-tracer.ts +1 -0
- package/src/behaviors/BComputedAndWatch/types.ts +0 -1
- package/src/index.ts +3 -1
- package/src/types/Assign.ts +1 -0
- package/src/types/OfficialTypeAlias.ts +1 -1
- package/dist/api/InstanceInject/InstanceInject.d.ts +0 -0
- package/dist/api/InstanceInject/InstanceInject.js +0 -2
- package/dist/api/InstanceInject/InstanceInject.js.map +0 -1
- package/dist/api/InstanceInject/test/InjectConfig.d.ts +0 -0
- package/dist/api/InstanceInject/test/InjectConfig.js +0 -2
- package/dist/api/InstanceInject/test/InjectConfig.js.map +0 -1
- package/src/api/InstanceInject/InstanceInject.ts +0 -25
- package/src/api/InstanceInject/test/InjectConfig.ts +0 -50
|
@@ -3,9 +3,11 @@ import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
|
|
|
3
3
|
import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
|
|
4
4
|
import type { ComputedCache, Instance } from "../../behaviors/BComputedAndWatch/types";
|
|
5
5
|
import { BStore } from "../../behaviors/BStore";
|
|
6
|
+
import { Assign } from "../../types/Assign";
|
|
6
7
|
import type { WMComponent } from "../../types/OfficialTypeAlias";
|
|
7
8
|
import { INNERMARKER } from "../../utils/InnerMarker";
|
|
8
9
|
import { isEmptyObject } from "../../utils/isEmptyObject";
|
|
10
|
+
import { instanceConfig } from "../InstanceInject/instanceConfig";
|
|
9
11
|
import type { RootComponentTrueOptions } from "../RootComponent";
|
|
10
12
|
import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
|
|
11
13
|
import type {
|
|
@@ -292,6 +294,44 @@ function collectRootComponentOption(
|
|
|
292
294
|
otherFieldsHandle(finalOptions, rootComponentOptions);
|
|
293
295
|
}
|
|
294
296
|
|
|
297
|
+
/**
|
|
298
|
+
* 合并 source 对象字段到 target字段
|
|
299
|
+
* @remarks 规则:
|
|
300
|
+
* 1. behaviors字段 源对象在前
|
|
301
|
+
* 2. 对象字段 源覆盖目标
|
|
302
|
+
* @param target - 目标对象
|
|
303
|
+
* @param source - 源对象
|
|
304
|
+
* @returns 按规则合并后的对象
|
|
305
|
+
*/
|
|
306
|
+
function merge<Target extends object, Source extends object>(target: Target, source: Source): Assign<Target, Source> {
|
|
307
|
+
for (const key in source) {
|
|
308
|
+
const sourceVal = source[key];
|
|
309
|
+
if (key in target) {
|
|
310
|
+
// @ts-ignore
|
|
311
|
+
const targetVal = target[key];
|
|
312
|
+
switch (key) {
|
|
313
|
+
case "behaviors":
|
|
314
|
+
{
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
target[key] = [...sourceVal, ...targetVal];
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
|
|
320
|
+
default:
|
|
321
|
+
{
|
|
322
|
+
// @ts-ignore 源覆盖目标
|
|
323
|
+
target[key] = Object.assign(targetVal, sourceVal);
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
// @ts-ignore
|
|
329
|
+
target[key] = sourceVal;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return target as unknown as Assign<Target, Source>;
|
|
334
|
+
}
|
|
295
335
|
/**
|
|
296
336
|
* 返回一个由rootComponentOption和subComponentsList配置整合的对象
|
|
297
337
|
* @param rootComponentOption -
|
|
@@ -303,18 +343,14 @@ export function collectOptionsForComponent(
|
|
|
303
343
|
): FinalOptionsOfComponent {
|
|
304
344
|
const rootComponentOption = defineComponentOption.rootComponent;
|
|
305
345
|
const subComponentsList = defineComponentOption.subComponents;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
addGlobalClass: true, // "styleIsolation": "apply-shared"
|
|
309
|
-
multipleSlots: true,
|
|
310
|
-
pureDataPattern: /^_/,
|
|
311
|
-
virtualHost: true,
|
|
312
|
-
},
|
|
313
|
-
behaviors: [BStore, BComputedAndWatch],
|
|
314
|
-
methods: {},
|
|
346
|
+
|
|
347
|
+
const finalOptionsForComponent: FinalOptionsOfComponent = merge(instanceConfig.injectInfo || {}, {
|
|
315
348
|
observers: {},
|
|
316
349
|
data: {},
|
|
317
|
-
|
|
350
|
+
methods: {},
|
|
351
|
+
behaviors: [BStore, BComputedAndWatch],
|
|
352
|
+
});
|
|
353
|
+
|
|
318
354
|
/**
|
|
319
355
|
* 有些字段配置同时存在根组件和子组件当中(如pageLifetimes,lifetimes,watch字段), 且key相同值类型为函数。funcConfig对象用于收集这些配置为数组形式,最终再一起整合进finalOptionsForComponent配置中。即funcConfig是一个临时中介对象。
|
|
320
356
|
*/
|
|
@@ -350,7 +386,7 @@ export function collectOptionsForComponent(
|
|
|
350
386
|
/* istanbul ignore next: miniprogram-simulate(当前版本 1.6.1) 无法测试页面 */
|
|
351
387
|
finalOptionsForComponent.isPage
|
|
352
388
|
// 页面时删除预设的虚拟组件字段
|
|
353
|
-
&& Reflect.deleteProperty(finalOptionsForComponent.options
|
|
389
|
+
&& finalOptionsForComponent.options && Reflect.deleteProperty(finalOptionsForComponent.options, "virtualHost");
|
|
354
390
|
|
|
355
391
|
// BBeforeCreate在最后面,让BeforeCreate生命周期运行在最终建立组件时。
|
|
356
392
|
finalOptionsForComponent.behaviors!.push(BBeforeCreate);
|
|
@@ -54,6 +54,7 @@ export type DefineComponentOption = {
|
|
|
54
54
|
*/
|
|
55
55
|
export const DefineComponent: DefineComponentConstructor = function(options): any {
|
|
56
56
|
// console.log("---------------------------");
|
|
57
|
+
|
|
57
58
|
Component(
|
|
58
59
|
collectOptionsForComponent(options as DefineComponentOption) as any,
|
|
59
60
|
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { observable, runInAction } from "mobx";
|
|
2
|
+
|
|
3
|
+
// 注入的响应式数据;
|
|
4
|
+
const themeStore = observable({ theme: wx.getSystemInfoSync().theme });
|
|
5
|
+
|
|
6
|
+
wx.onThemeChange((Res) => {
|
|
7
|
+
runInAction(() => {
|
|
8
|
+
themeStore.theme = Res.theme;
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// 注入的方法;
|
|
13
|
+
function injectMethod(data: string) {
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const data = {
|
|
18
|
+
injectStr: "injectStr",
|
|
19
|
+
};
|
|
20
|
+
const methods = {
|
|
21
|
+
injectMethod,
|
|
22
|
+
};
|
|
23
|
+
const store = {
|
|
24
|
+
injectTheme: () => themeStore.theme,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 声明注入类型 js开发可以忽略
|
|
28
|
+
declare module "../.." {
|
|
29
|
+
interface IInjectInfo {
|
|
30
|
+
data: typeof data;
|
|
31
|
+
store: typeof store;
|
|
32
|
+
methods: typeof methods;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
|
|
2
|
+
|
|
3
|
+
import { ReturnTypeInObject } from "hry-types/src/Object/ReturnTypeInObject";
|
|
4
|
+
import { WMComponentOption } from "../../types/OfficialTypeAlias";
|
|
5
|
+
import { DataConstraint } from "../RootComponent/Data/DataConstraint";
|
|
6
|
+
import { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
|
|
7
|
+
import { StoreConstraint } from "../RootComponent/Store/StoreConstraint";
|
|
8
|
+
|
|
9
|
+
// 利用继承的多态性 使得IInjectInfo类型可由使用者外部定义
|
|
10
|
+
interface BaseInjectInfo {
|
|
11
|
+
options?: WMComponentOption;
|
|
12
|
+
methods?: MethodsConstraint;
|
|
13
|
+
data?: DataConstraint;
|
|
14
|
+
store?: StoreConstraint;
|
|
15
|
+
behaviors?: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
19
|
+
export interface IInjectInfo extends BaseInjectInfo {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type IInjectData = IInjectInfo["data"] & ReturnTypeInObject<IInjectInfo["store"]>;
|
|
23
|
+
|
|
24
|
+
export type IInjectMethods = IInjectInfo["methods"];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 实例配置接口
|
|
28
|
+
*/
|
|
29
|
+
class InstanceConfig {
|
|
30
|
+
private info: { injectInfo?: IInjectInfo } = {};
|
|
31
|
+
public get injectInfo() {
|
|
32
|
+
return this.info.injectInfo;
|
|
33
|
+
}
|
|
34
|
+
public setInjectInfo(info: IInjectInfo | undefined) {
|
|
35
|
+
info && (this.info.injectInfo = info);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const instanceConfig = new InstanceConfig();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Checking, Test } from "hry-types";
|
|
2
|
+
import { RootComponent } from "../../RootComponent";
|
|
3
|
+
|
|
4
|
+
// 1. 注入字段无重复时
|
|
5
|
+
RootComponent()({
|
|
6
|
+
methods: {
|
|
7
|
+
testInjectTypes() {
|
|
8
|
+
Checking<typeof this.data.injectStr, string, Test.Pass>;
|
|
9
|
+
|
|
10
|
+
Checking<typeof this.data.injectTheme, "dark" | "light" | undefined, Test.Pass>;
|
|
11
|
+
|
|
12
|
+
Checking<typeof this.injectMethod, (data: string) => string, Test.Pass>;
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// 2. 注入字段重复时,自身覆盖注入类型
|
|
18
|
+
RootComponent()({
|
|
19
|
+
data: {
|
|
20
|
+
// 覆盖注入的数据类型
|
|
21
|
+
injectStr: 123,
|
|
22
|
+
},
|
|
23
|
+
store: {
|
|
24
|
+
// 覆盖注入的数据类型
|
|
25
|
+
injectTheme: (() => "aaa") as () => "aaa",
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
// 覆盖注入的方法类型
|
|
29
|
+
injectMethod() {
|
|
30
|
+
return 123;
|
|
31
|
+
},
|
|
32
|
+
testInjectTypes() {
|
|
33
|
+
Checking<typeof this.data.injectStr, number, Test.Pass>;
|
|
34
|
+
|
|
35
|
+
Checking<typeof this.data.injectTheme, "aaa", Test.Pass>;
|
|
36
|
+
|
|
37
|
+
Checking<typeof this.injectMethod, () => 123, Test.Pass>;
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
3
4
|
import { RootComponent } from "../..";
|
|
4
5
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
5
6
|
|
|
@@ -29,15 +30,17 @@ const RootDoc = RootComponent()({
|
|
|
29
30
|
// 3 this.data 类型是深度只读的
|
|
30
31
|
Checking<
|
|
31
32
|
typeof this.data,
|
|
32
|
-
ReadonlyDeep<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
ReadonlyDeep<
|
|
34
|
+
{
|
|
35
|
+
firstName: string;
|
|
36
|
+
lastName: string;
|
|
37
|
+
fullName: string;
|
|
38
|
+
user: Mock_User;
|
|
39
|
+
prefix: string;
|
|
40
|
+
id_fullName: string;
|
|
41
|
+
readOnly: "str";
|
|
42
|
+
} & IInjectData
|
|
43
|
+
>,
|
|
41
44
|
Test.Pass
|
|
42
45
|
>;
|
|
43
46
|
|
|
@@ -66,7 +69,7 @@ const noComputedFieldDoc = RootComponent()({
|
|
|
66
69
|
methods: {
|
|
67
70
|
M1() {
|
|
68
71
|
// 5.1 无computed,this.data中为{}
|
|
69
|
-
Checking<typeof this.data,
|
|
72
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
70
73
|
},
|
|
71
74
|
},
|
|
72
75
|
});
|
|
@@ -81,7 +84,7 @@ const EmptyComputedFieldDoc = RootComponent()({
|
|
|
81
84
|
methods: {
|
|
82
85
|
M1() {
|
|
83
86
|
// 6.1 computed为{},this.data中为{}
|
|
84
|
-
Checking<typeof this.data,
|
|
87
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
85
88
|
},
|
|
86
89
|
},
|
|
87
90
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
3
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
4
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
4
5
|
import { RootComponent } from "../..";
|
|
5
6
|
|
|
6
7
|
type Gender = "male" | "female";
|
|
@@ -15,7 +16,7 @@ const RootDoc = RootComponent()({
|
|
|
15
16
|
foo() {
|
|
16
17
|
Checking<
|
|
17
18
|
typeof this.data,
|
|
18
|
-
ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number }>,
|
|
19
|
+
ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number } & IInjectData>,
|
|
19
20
|
Test.Pass
|
|
20
21
|
>;
|
|
21
22
|
},
|
|
@@ -36,7 +37,7 @@ const EmptyDataRootDoc = RootComponent()({
|
|
|
36
37
|
methods: {
|
|
37
38
|
M1() {
|
|
38
39
|
// 3.1 data为空对象时 this.data为{}类型
|
|
39
|
-
Checking<typeof this.data,
|
|
40
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
40
41
|
},
|
|
41
42
|
},
|
|
42
43
|
});
|
|
@@ -51,7 +52,7 @@ const noDataRootDoc = RootComponent()({
|
|
|
51
52
|
methods: {
|
|
52
53
|
M1() {
|
|
53
54
|
// 4.1 data为空对象时 this.data为{}类型
|
|
54
|
-
Checking<typeof this.data,
|
|
55
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
55
56
|
},
|
|
56
57
|
},
|
|
57
58
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
2
2
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
3
|
-
import type { Func } from "hry-types/src/Misc/Func";
|
|
4
3
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
5
4
|
import type { IReactionDisposer } from "mobx";
|
|
6
5
|
|
|
6
|
+
import { Assign } from "../../../types/Assign";
|
|
7
7
|
import type { WMComponentInstance, WMInstanceMethods, WMPageInstance } from "../../../types/OfficialTypeAlias";
|
|
8
|
+
import { IInjectData, IInjectMethods } from "../../InstanceInject/instanceConfig";
|
|
8
9
|
import type { CustomEventMethods } from "./CustomEventMethods";
|
|
9
10
|
import type { CustomSetData } from "./CustomSetData";
|
|
10
11
|
export type RootComponentInstance<
|
|
@@ -23,11 +24,9 @@ export type RootComponentInstance<
|
|
|
23
24
|
& CustomSetData<TData>
|
|
24
25
|
& IfExtends<{}, StoreDoc, unknown, {
|
|
25
26
|
disposer?: { [k in keyof StoreDoc]: IReactionDisposer };
|
|
26
|
-
applySetData: Func;
|
|
27
27
|
}>
|
|
28
|
-
& TMethods
|
|
29
|
-
&
|
|
30
|
-
& { data: ReadonlyDeep<ComputeIntersection<AllData>> };
|
|
28
|
+
& Assign<IInjectMethods, TMethods & CustomEventMethods<CustomEventsDoc>>
|
|
29
|
+
& { data: ReadonlyDeep<Assign<IInjectData, ComputeIntersection<AllData>>> };
|
|
31
30
|
|
|
32
31
|
export type ComponentInstance = RootComponentInstance<false, {}, {}, {}, {}, {}>;
|
|
33
32
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
3
3
|
import { type DetailedType, RootComponent } from "../../../../..";
|
|
4
|
+
import { IInjectData } from "../../../../InstanceInject/instanceConfig";
|
|
4
5
|
|
|
5
6
|
// 组件时
|
|
6
7
|
RootComponent()({
|
|
@@ -14,7 +15,11 @@ RootComponent()({
|
|
|
14
15
|
lifetimes: {
|
|
15
16
|
attached() {
|
|
16
17
|
// 组件实例对象格外添加null类型
|
|
17
|
-
Checking<
|
|
18
|
+
Checking<
|
|
19
|
+
typeof this.data,
|
|
20
|
+
ReadonlyDeep<{ optionalObj: { name: string } | null; obj: object | null } & IInjectData>,
|
|
21
|
+
Test.Pass
|
|
22
|
+
>;
|
|
18
23
|
},
|
|
19
24
|
},
|
|
20
25
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Checking, Test } from "hry-types";
|
|
1
2
|
import { RootComponent } from "../../../..";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -7,6 +8,8 @@ RootComponent()({
|
|
|
7
8
|
lifetimes: {
|
|
8
9
|
// 新增声明周期可用于查看或拓展配置文件
|
|
9
10
|
beforeCreate(opitons) {
|
|
11
|
+
Checking<typeof this, void, Test.Pass>;
|
|
12
|
+
|
|
10
13
|
opitons;
|
|
11
14
|
},
|
|
12
15
|
created() {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
+
import { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
2
4
|
import { RootComponent } from "../..";
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -9,7 +11,7 @@ const emptyObj = RootComponent()({
|
|
|
9
11
|
methods: {
|
|
10
12
|
foo() {
|
|
11
13
|
// 1 this.data 为空对象类型
|
|
12
|
-
Checking<typeof this.data,
|
|
14
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
13
15
|
},
|
|
14
16
|
},
|
|
15
17
|
});
|
|
@@ -28,7 +30,7 @@ const noProperties = RootComponent()({
|
|
|
28
30
|
methods: {
|
|
29
31
|
foo() {
|
|
30
32
|
// 3 this.data 为空对象类型
|
|
31
|
-
Checking<typeof this.data,
|
|
33
|
+
Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
|
|
32
34
|
},
|
|
33
35
|
},
|
|
34
36
|
});
|
|
@@ -1,6 +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 { DetailedType } from "../../../../types/DetailedType";
|
|
4
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
4
5
|
import { RootComponent } from "../..";
|
|
5
6
|
import { type Mock_User } from "./normalRequired.test";
|
|
6
7
|
|
|
@@ -43,14 +44,16 @@ const OptionalDoc = RootComponent()({
|
|
|
43
44
|
// 1. 内部this.data中的类型(去除可选)
|
|
44
45
|
Checking<
|
|
45
46
|
typeof this.data,
|
|
46
|
-
ReadonlyDeep<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
ReadonlyDeep<
|
|
48
|
+
{
|
|
49
|
+
optional_num: number;
|
|
50
|
+
optional_gender: "male" | "female";
|
|
51
|
+
optional_tuple: [number, string, boolean];
|
|
52
|
+
optional_obj: Mock_User | null;
|
|
53
|
+
optional_objOrNull: Mock_User | null;
|
|
54
|
+
optional_union: string | number;
|
|
55
|
+
} & IInjectData
|
|
56
|
+
>,
|
|
54
57
|
Test.Pass
|
|
55
58
|
>;
|
|
56
59
|
},
|
|
@@ -2,6 +2,7 @@ import { Checking, type Test } from "hry-types";
|
|
|
2
2
|
import type { DetailedType } from "../../../../types/DetailedType";
|
|
3
3
|
|
|
4
4
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
5
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
5
6
|
import { RootComponent } from "../..";
|
|
6
7
|
import type { RequiredSingle, RequiredType, RequiredUnion } from "../PropertiesConstraint";
|
|
7
8
|
|
|
@@ -91,7 +92,7 @@ const RequiredDoc = RootComponent()({
|
|
|
91
92
|
methods: {
|
|
92
93
|
foo() {
|
|
93
94
|
// 1 this.data中的类型(对象类型加null)
|
|
94
|
-
Checking<typeof this.data, ReadonlyDeep<RequiredTypeExpected>, Test.Pass>;
|
|
95
|
+
Checking<typeof this.data, ReadonlyDeep<RequiredTypeExpected & IInjectData>, Test.Pass>;
|
|
95
96
|
},
|
|
96
97
|
},
|
|
97
98
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Checking, Test } from "hry-types";
|
|
2
|
+
import { RootComponent } from "../..";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* watch data字段 深度只读
|
|
6
|
+
*/
|
|
7
|
+
RootComponent()({
|
|
8
|
+
watch: {
|
|
9
|
+
injectStr(newValue, oldValue) {
|
|
10
|
+
Checking<string, typeof newValue, Test.Pass>;
|
|
11
|
+
|
|
12
|
+
Checking<string, typeof oldValue, Test.Pass>;
|
|
13
|
+
},
|
|
14
|
+
injectTheme(newValue, oldValue) {
|
|
15
|
+
Checking<"dark" | "light" | undefined, typeof newValue, Test.Pass>;
|
|
16
|
+
|
|
17
|
+
Checking<"dark" | "light" | undefined, typeof oldValue, Test.Pass>;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -5,6 +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 { IInjectData } from "../InstanceInject/instanceConfig";
|
|
8
9
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
9
10
|
import type { ComputedOption } from "./Computed/ComputedOption";
|
|
10
11
|
import type { GetComputedDoc } from "./Computed/GetComputedDoc";
|
|
@@ -61,6 +62,7 @@ type RootComponentOptions<
|
|
|
61
62
|
& Required<PropertiesDoc>
|
|
62
63
|
& DataDoc
|
|
63
64
|
& StoreDoc
|
|
65
|
+
& IInjectData
|
|
64
66
|
>
|
|
65
67
|
& Partial<Omit<WMCompOtherOption, "pageLifetimes">>
|
|
66
68
|
& ThisType<
|
|
@@ -2,6 +2,7 @@ import { Checking, type Test } from "hry-types";
|
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
3
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
4
4
|
|
|
5
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
5
6
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
6
7
|
import { SubComponent } from "../..";
|
|
7
8
|
|
|
@@ -80,17 +81,19 @@ SubComponent<Root, OnlyPropsCompDoc>()({
|
|
|
80
81
|
// 5 this.data
|
|
81
82
|
Checking<
|
|
82
83
|
typeof this.data,
|
|
83
|
-
ReadonlyDeep<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
ReadonlyDeep<
|
|
85
|
+
{
|
|
86
|
+
num: number;
|
|
87
|
+
user: User | null;
|
|
88
|
+
SNum: number;
|
|
89
|
+
str: string;
|
|
90
|
+
bool: boolean;
|
|
91
|
+
aaa_num: number;
|
|
92
|
+
aaa_num123: 123;
|
|
93
|
+
aaa_str: "a";
|
|
94
|
+
aaa_obj: Mock_User;
|
|
95
|
+
} & IInjectData
|
|
96
|
+
>,
|
|
94
97
|
Test.Pass
|
|
95
98
|
>;
|
|
96
99
|
|
|
@@ -102,17 +105,19 @@ SubComponent<Root, OnlyPropsCompDoc>()({
|
|
|
102
105
|
// 5 this.data 深度只读
|
|
103
106
|
Checking<
|
|
104
107
|
typeof this.data,
|
|
105
|
-
ReadonlyDeep<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
ReadonlyDeep<
|
|
109
|
+
{
|
|
110
|
+
num: number;
|
|
111
|
+
user: User | null;
|
|
112
|
+
str: string;
|
|
113
|
+
SNum: number;
|
|
114
|
+
bool: boolean;
|
|
115
|
+
aaa_num: number;
|
|
116
|
+
aaa_num123: 123;
|
|
117
|
+
aaa_str: "a";
|
|
118
|
+
aaa_obj: Mock_User;
|
|
119
|
+
} & IInjectData
|
|
120
|
+
>,
|
|
116
121
|
Test.Pass
|
|
117
122
|
>;
|
|
118
123
|
},
|
|
@@ -2,6 +2,7 @@ import { Checking, type Test } from "hry-types";
|
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
3
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
4
4
|
|
|
5
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
5
6
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
6
7
|
import { SubComponent } from "../..";
|
|
7
8
|
|
|
@@ -51,12 +52,14 @@ SubComponent<{}, CompDoc>()({
|
|
|
51
52
|
// 4 this.data中的data配置数据
|
|
52
53
|
Checking<
|
|
53
54
|
typeof this.data,
|
|
54
|
-
ReadonlyDeep<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
ReadonlyDeep<
|
|
56
|
+
{
|
|
57
|
+
aaa_str: "a";
|
|
58
|
+
aaa_num: 123;
|
|
59
|
+
aaa_obj: null;
|
|
60
|
+
_aaa_str: string;
|
|
61
|
+
} & IInjectData
|
|
62
|
+
>,
|
|
60
63
|
Test.Pass
|
|
61
64
|
>;
|
|
62
65
|
},
|
|
@@ -2,6 +2,7 @@ import { Checking, type Test } from "hry-types";
|
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
3
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
4
4
|
|
|
5
|
+
import { IInjectData } from "../../../InstanceInject/instanceConfig";
|
|
5
6
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
6
7
|
import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
|
|
7
8
|
import { SubComponent } from "../..";
|
|
@@ -57,17 +58,19 @@ SubComponent<RootDoc, CompDoc>()({
|
|
|
57
58
|
// this.data
|
|
58
59
|
Checking<
|
|
59
60
|
typeof this.data,
|
|
60
|
-
ReadonlyDeep<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
ReadonlyDeep<
|
|
62
|
+
{
|
|
63
|
+
// RootData
|
|
64
|
+
Pstr: string;
|
|
65
|
+
Pobj: Mock_User | null;
|
|
66
|
+
PoptionalObj: Mock_User;
|
|
67
|
+
Dnum: number;
|
|
68
|
+
Cnum: number;
|
|
69
|
+
// 自身Data
|
|
70
|
+
aaa_str: "str";
|
|
71
|
+
_aaa_SubReactive: 123;
|
|
72
|
+
} & IInjectData
|
|
73
|
+
>,
|
|
71
74
|
Test.Pass
|
|
72
75
|
>;
|
|
73
76
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NoInfer } from "hry-types/src/Generic/NoInfer";
|
|
2
1
|
import type { WatchOption } from "../../RootComponent/Watch/WatchOption";
|
|
3
2
|
|
|
4
|
-
export type SubWatchOption<TWatchData extends object> = WatchOption<
|
|
3
|
+
export type SubWatchOption<TWatchData extends object> = WatchOption<TWatchData>;
|