annil 1.12.7 → 1.13.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/ChunkComponent/ChunkStore/ChunkStoreOption.d.ts +2 -1
  3. package/dist/api/ChunkComponent/index.d.ts +3 -3
  4. package/dist/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.d.ts +1 -1
  5. package/dist/api/CustomComponent/CustomStore/CustomStoreConstraint.d.ts +3 -2
  6. package/dist/api/CustomComponent/CustomStore/CustomStoreOption.d.ts +1 -3
  7. package/dist/api/CustomComponent/index.d.ts +4 -3
  8. package/dist/api/CustomComponent/index.js.map +1 -1
  9. package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js +4 -19
  10. package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js.map +1 -1
  11. package/dist/api/RootComponent/Computed/{GetComputedDoc.d.ts → GetComputedDef.d.ts} +1 -1
  12. package/dist/api/RootComponent/Computed/GetComputedDef.js +2 -0
  13. package/dist/api/RootComponent/Computed/GetComputedDef.js.map +1 -0
  14. package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +10 -5
  15. package/dist/api/RootComponent/CustomEvents/CustomEventsTag.d.ts +2 -2
  16. package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.d.ts +10 -0
  17. package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.js +2 -0
  18. package/dist/api/RootComponent/CustomEvents/GetCustomEventDef.js.map +1 -0
  19. package/dist/api/RootComponent/Events/EventsConstraint.d.ts +2 -2
  20. package/dist/api/RootComponent/Instance/CustomEventMethods.d.ts +2 -2
  21. package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
  22. package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +1 -1
  23. package/dist/api/RootComponent/Properties/{GetOptionalDoc.d.ts → GetOptionalDef.d.ts} +1 -1
  24. package/dist/api/RootComponent/Properties/GetOptionalDef.js +2 -0
  25. package/dist/api/RootComponent/Properties/GetOptionalDef.js.map +1 -0
  26. package/dist/api/RootComponent/Properties/GetPropertiesDef.d.ts +8 -0
  27. package/dist/api/RootComponent/Properties/GetPropertiesDef.js +2 -0
  28. package/dist/api/RootComponent/Properties/GetPropertiesDef.js.map +1 -0
  29. package/dist/api/RootComponent/Properties/GetRequiredDef.d.ts +5 -0
  30. package/dist/api/RootComponent/Properties/GetRequiredDef.js +2 -0
  31. package/dist/api/RootComponent/Properties/GetRequiredDef.js.map +1 -0
  32. package/dist/api/RootComponent/Store/{GeTStoreDoc.d.ts → GetStoreDef.d.ts} +1 -1
  33. package/dist/api/RootComponent/Store/GetStoreDef.js +3 -0
  34. package/dist/api/RootComponent/Store/GetStoreDef.js.map +1 -0
  35. package/dist/api/RootComponent/Store/StoreConstraint.d.ts +1 -5
  36. package/dist/api/RootComponent/Store/StoreOption.d.ts +1 -12
  37. package/dist/api/RootComponent/index.d.ts +19 -19
  38. package/dist/api/wxSugar.d.ts +1 -1
  39. package/dist/index.d.ts +1 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/thirdLib/vant/Popup.d.ts +1 -1
  42. package/dist/thirdLib/wm/Textarea.d.ts +1 -1
  43. package/dist/thirdLib/wm/swiper.d.ts +1 -1
  44. package/dist/types/AddNullForObject.d.ts +2 -0
  45. package/dist/types/AddNullForObject.js +2 -0
  46. package/dist/types/AddNullForObject.js.map +1 -0
  47. package/dist/types/ComputeObject.js +2 -0
  48. package/dist/types/ComputeObject.js.map +1 -0
  49. package/dist/types/Replace.d.ts +8 -0
  50. package/dist/types/Replace.js +2 -0
  51. package/dist/types/Replace.js.map +1 -0
  52. package/dist/utils/nonNullable.d.ts +1 -1
  53. package/dist/utils/nonNullable.js +2 -2
  54. package/dist/utils/nonNullable.js.map +1 -1
  55. package/dist/utils/typeEqual.d.ts +1 -1
  56. package/dist/utils/typeEqual.js +2 -2
  57. package/dist/utils/typeEqual.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/api/ChunkComponent/ChunkComputed/test/normal.test.ts +1 -1
  60. package/src/api/ChunkComponent/ChunkStore/ChunkStoreOption.ts +2 -1
  61. package/src/api/ChunkComponent/ChunkStore/test/error.test.ts +3 -31
  62. package/src/api/ChunkComponent/ChunkStore/test/normal.test.ts +40 -41
  63. package/src/api/ChunkComponent/index.ts +4 -4
  64. package/src/api/CustomComponent/CustomData/test/normal.test.ts +7 -4
  65. package/src/api/CustomComponent/CustomReturnType/CreateCustomComponentDoc.ts +1 -1
  66. package/src/api/CustomComponent/CustomStore/CustomStoreConstraint.ts +3 -2
  67. package/src/api/CustomComponent/CustomStore/CustomStoreOption.ts +0 -2
  68. package/src/api/CustomComponent/CustomStore/test/error.test.ts +6 -46
  69. package/src/api/CustomComponent/CustomStore/test/normal.test.ts +0 -45
  70. package/src/api/CustomComponent/index.ts +7 -6
  71. package/src/api/DefineComponent/SubComponents/test/normal.test.ts +4 -4
  72. package/src/api/DefineComponent/index.ts +4 -4
  73. package/src/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.ts +5 -20
  74. package/src/api/DefineComponent/returnType/test/normalPageDoc.test.ts +0 -1
  75. package/src/api/RootComponent/Computed/ComputedOption.ts +2 -3
  76. package/src/api/RootComponent/Computed/{GetComputedDoc.ts → GetComputedDef.ts} +1 -1
  77. package/src/api/RootComponent/Computed/test/GetComputedDoc.test.ts +3 -3
  78. package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +20 -5
  79. package/src/api/RootComponent/CustomEvents/CustomEventsDef.ts +4 -0
  80. package/src/api/RootComponent/CustomEvents/CustomEventsTag.ts +2 -2
  81. package/src/api/RootComponent/CustomEvents/GetCustomEventDef.ts +29 -0
  82. package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +3 -3
  83. package/src/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.ts +2 -2
  84. package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +6 -6
  85. package/src/api/RootComponent/CustomEvents/test/normal.test.ts +8 -8
  86. package/src/api/RootComponent/Data/GetDataDef.ts +8 -0
  87. package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +3 -3
  88. package/src/api/RootComponent/Events/EventsConstraint.ts +3 -3
  89. package/src/api/RootComponent/Events/EventsOption.ts +2 -2
  90. package/src/api/RootComponent/Events/test/normal.test.ts +16 -0
  91. package/src/api/RootComponent/Instance/CustomEventMethods.ts +4 -4
  92. package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -4
  93. package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +1 -1
  94. package/src/api/RootComponent/Properties/{GetOptionalDoc.ts → GetOptionalDef.ts} +1 -1
  95. package/src/api/RootComponent/Properties/GetPropertiesDef.ts +25 -0
  96. package/src/api/RootComponent/Properties/GetRequiredDef.ts +16 -0
  97. package/src/api/RootComponent/Store/{GeTStoreDoc.ts → GetStoreDef.ts} +10 -14
  98. package/src/api/RootComponent/Store/StoreConstraint.ts +1 -7
  99. package/src/api/RootComponent/Store/StoreOption.ts +6 -40
  100. package/src/api/RootComponent/Store/test/error.test.ts +3 -38
  101. package/src/api/RootComponent/Store/test/normal.test.ts +0 -46
  102. package/src/api/RootComponent/index.ts +50 -50
  103. package/src/api/wxSugar.ts +1 -1
  104. package/src/index.ts +1 -2
  105. package/src/thirdLib/vant/Popup.ts +1 -1
  106. package/src/thirdLib/wm/Textarea.ts +1 -1
  107. package/src/thirdLib/wm/swiper.test.ts +22 -0
  108. package/src/thirdLib/wm/swiper.ts +1 -1
  109. package/src/types/CreateComponentType.ts +2 -2
  110. package/src/types/ExtendComponentType.ts +5 -5
  111. package/src/utils/nonNullable.ts +4 -1
  112. package/src/utils/typeEqual.ts +11 -8
  113. package/src/utils/typeNotEqual.ts +48 -0
  114. package/dist/api/RootComponent/Computed/GetComputedDoc.js +0 -2
  115. package/dist/api/RootComponent/Computed/GetComputedDoc.js.map +0 -1
  116. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +0 -10
  117. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.js +0 -2
  118. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.js.map +0 -1
  119. package/dist/api/RootComponent/Properties/GetOptionalDoc.js +0 -2
  120. package/dist/api/RootComponent/Properties/GetOptionalDoc.js.map +0 -1
  121. package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +0 -8
  122. package/dist/api/RootComponent/Properties/GetPropertiesDoc.js +0 -2
  123. package/dist/api/RootComponent/Properties/GetPropertiesDoc.js.map +0 -1
  124. package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +0 -6
  125. package/dist/api/RootComponent/Properties/GetRequiredDoc.js +0 -2
  126. package/dist/api/RootComponent/Properties/GetRequiredDoc.js.map +0 -1
  127. package/dist/api/RootComponent/Store/GeTStoreDoc.js +0 -2
  128. package/dist/api/RootComponent/Store/GeTStoreDoc.js.map +0 -1
  129. package/dist/types/ComputeObj.js +0 -2
  130. package/dist/types/ComputeObj.js.map +0 -1
  131. package/dist/types/TwoParamsEqual.d.ts +0 -2
  132. package/dist/types/TwoParamsEqual.js +0 -2
  133. package/dist/types/TwoParamsEqual.js.map +0 -1
  134. package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +0 -24
  135. package/src/api/RootComponent/Properties/GetRequiredDoc.ts +0 -23
  136. /package/dist/types/{ComputeObj.d.ts → ComputeObject.d.ts} +0 -0
  137. /package/src/types/{ComputeObj.ts → ComputeObject.ts} +0 -0
@@ -26,7 +26,7 @@ export type Swiper = CreateComponentType<"swiper", {
26
26
  displayMultipleItems?: number;
27
27
  easingFunction?: "defaultValue" | "linear" | "easeInCubic" | "easeOutCubic" | "easeInOutCubic";
28
28
  };
29
- customEvents: {
29
+ events: {
30
30
  change: ChangeEventDetail;
31
31
  transition: {
32
32
  dx: number;
@@ -0,0 +1,2 @@
1
+ import type { IsPureObject } from "hry-types/src/Any/IsPureObject";
2
+ export type AddNullForObject<O> = O extends unknown ? IsPureObject<O> extends true ? (O | null) : O : never;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AddNullForObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddNullForObject.js","sourceRoot":"","sources":["../../src/types/AddNullForObject.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ComputeObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComputeObject.js","sourceRoot":"","sources":["../../src/types/ComputeObject.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
2
+ type _Replace<Target, Source, DifferentKeys extends keyof Target, SameKey extends keyof Source> = ComputeIntersection<{
3
+ [k in DifferentKeys]: Target[k];
4
+ } & {
5
+ [k in SameKey]: Source[k];
6
+ }>;
7
+ export type Replace<Target extends object, Source extends object> = _Replace<Target, Source, Exclude<keyof Target, keyof Source>, Extract<keyof Target, keyof Source>>;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Replace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Replace.js","sourceRoot":"","sources":["../../src/types/Replace.ts"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
1
  import type { IfContains } from "hry-types/src/Any/IfContains";
2
- export declare function nonNullable<T>(value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined">): NonNullable<T>;
2
+ export declare function nonNullable<T>(value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined">, message?: string): NonNullable<T>;
@@ -1,6 +1,6 @@
1
- export function nonNullable(value) {
1
+ export function nonNullable(value, message) {
2
2
  if (value === null || value === undefined) {
3
- throw new Error(`${value} should not be null or undefined`);
3
+ throw new Error(message !== null && message !== void 0 ? message : `${value} should not be null or undefined`);
4
4
  }
5
5
  return value;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nonNullable.js","sourceRoot":"","sources":["../../src/utils/nonNullable.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,WAAW,CACzB,KAAsE;IAGtE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,KAAuB,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"nonNullable.js","sourceRoot":"","sources":["../../src/utils/nonNullable.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,WAAW,CACzB,KAAsE,EACtE,OAAgB;IAGhB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,GAAG,KAAK,kCAAkC,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,KAAuB,CAAC;AACjC,CAAC"}
@@ -1,2 +1,2 @@
1
1
  import type { Equals } from "hry-types/src/Any/Equals";
2
- export declare function typeEqual<A, B extends Equals<A, B> extends true ? unknown : never>(): void;
2
+ export declare function typeEqual<const A, const B extends Equals<A, B> extends true ? unknown : never = never>(a?: NoInfer<A>): void;
@@ -1,4 +1,4 @@
1
- export function typeEqual() {
2
- void 0;
1
+ export function typeEqual(a) {
2
+ void a;
3
3
  }
4
4
  //# sourceMappingURL=typeEqual.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeEqual.js","sourceRoot":"","sources":["../../src/utils/typeEqual.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,SAAS;IAIvB,KAAK,CAAC,CAAC;AACT,CAAC"}
1
+ {"version":3,"file":"typeEqual.js","sourceRoot":"","sources":["../../src/utils/typeEqual.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,SAAS,CAGvB,CAAc;IACd,KAAK,CAAC,CAAC;AACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "annil",
3
- "version": "1.12.7",
3
+ "version": "1.13.1",
4
4
  "description": "微信小程序(原生开发)插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -1,5 +1,5 @@
1
1
  import { Checking } from "hry-types";
2
- import type { ComputeObject } from "../../../../types/ComputeObj";
2
+ import type { ComputeObject } from "../../../../types/ComputeObject";
3
3
  import type { IInjectAllData } from "../../../InstanceInject/instanceConfig";
4
4
  import { ChunkComponent } from "../..";
5
5
  import type { Mock_RootDoc } from "./mock";
@@ -2,9 +2,10 @@ import type { G } from "hry-types";
2
2
  import type { Validators } from "../../../types/Validators";
3
3
  import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
4
4
  import type { ValidatorPrefix } from "../ChunkData/validatePrefix";
5
+ import type { ChunkStoreConstraint } from "./ChunkStoreConstraint";
5
6
 
6
7
  export type ChunkStoreOption<
7
- TStore extends object,
8
+ TStore extends ChunkStoreConstraint,
8
9
  TDuplicateKeys extends PropertyKey,
9
10
  Prefix extends string,
10
11
  > = {
@@ -1,4 +1,3 @@
1
- import { observable } from "mobx";
2
1
  import { ChunkComponent } from "../..";
3
2
  import type { Mock_RootDoc } from "./mock";
4
3
 
@@ -28,37 +27,10 @@ ChunkComponent<Mock_RootDoc, "slot">()({
28
27
  },
29
28
  });
30
29
 
31
- type User = {
32
- name: string;
33
- age?: number;
34
- };
35
- type AllGoods = Record<string, User[] | undefined>;
36
- const M_User = observable({
37
- allUser: {
38
- categoryA: [{ name: "zhao", age: 20 }],
39
- categoryB: [{ name: "zhao" }],
40
- } as AllGoods,
41
- });
42
-
30
+ // 4. 返回类型错误
43
31
  ChunkComponent<{ properties: { categoryId: string } }>()({
44
32
  store: {
45
- // @ts-expect-error 1 响应式包含undefined时 不可以写成getter函数形式
46
- categoryList: (data) => M_User.allUser[data.categoryId],
47
-
48
- _categoryList: {
49
- // @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
50
- getter: (data) => M_User.allUser[data.categoryId] as User[],
51
- default: 0,
52
- },
53
- _categoryList1: {
54
- getter: (data) => M_User.allUser[data.categoryId],
55
- // @ts-expect-error 3 默认值应该为[]
56
- default: 0,
57
- },
58
- _categoryList2: {
59
- getter: (data) => M_User.allUser[data.categoryId]?.[0],
60
- // @ts-expect-error 3 对象类型错误 namesss
61
- default: { namesss: "zhao", age: 20 },
62
- },
33
+ // @ts-expect-error 4.1 返回类型中不可以包含undefined
34
+ categoryList: () => undefined,
63
35
  },
64
36
  });
@@ -1,4 +1,3 @@
1
- import { observable } from "mobx";
2
1
  import { ChunkComponent } from "../..";
3
2
  import type { Mock_RootDoc } from "./mock";
4
3
 
@@ -10,44 +9,44 @@ ChunkComponent<Mock_RootDoc, "slot">()({
10
9
  },
11
10
  });
12
11
 
13
- type User = {
14
- name: string;
15
- age?: number;
16
- };
17
- type AllGoods = Record<string, User[]>;
18
- const M_User = observable({
19
- allUser: {
20
- categoryA: [{ name: "zhao", age: 20 }],
21
- categoryB: [{ name: "zhao" }],
22
- } as AllGoods,
23
- });
12
+ // type User = {
13
+ // name: string;
14
+ // age?: number;
15
+ // };
16
+ // type AllGoods = Record<string, User[]>;
17
+ // const M_User = observable({
18
+ // allUser: {
19
+ // categoryA: [{ name: "zhao", age: 20 }],
20
+ // categoryB: [{ name: "zhao" }],
21
+ // } as AllGoods,
22
+ // });
24
23
 
25
- ChunkComponent<{ properties: { categoryId: string } }>()({
26
- data: {
27
- // categoryList:[],
28
- },
29
- store: {
30
- // 1 响应式不包含undefined时 只能写成getter函数形式
31
- categoryList: (data) => M_User.allUser[data.categoryId],
32
- // 2 响应式数据包含undefined时 只能写成对象形式
33
- _categoryList: {
34
- getter: (data) => M_User.allUser[data.categoryId][0].age,
35
- default: 0,
36
- },
37
- _categoryList1: {
38
- getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
39
- // 默认值为[]
40
- default: [],
41
- },
42
- _categoryList2: {
43
- getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
44
- // 对象类型 默认值为User类型
45
- default: { name: "zhao", age: 20 },
46
- },
47
- _categoryList3: {
48
- getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
49
- // 对象类型 默认值可以为null
50
- default: null,
51
- },
52
- },
53
- });
24
+ // ChunkComponent<{ properties: { categoryId: string } }>()({
25
+ // data: {
26
+ // // categoryList:[],
27
+ // },
28
+ // store: {
29
+ // // 1 响应式不包含undefined时 只能写成getter函数形式
30
+ // categoryList: (data) => M_User.allUser[data.categoryId],
31
+ // // 2 响应式数据包含undefined时 只能写成对象形式
32
+ // _categoryList: {
33
+ // getter: (data) => M_User.allUser[data.categoryId][0].age,
34
+ // default: 0,
35
+ // },
36
+ // _categoryList1: {
37
+ // getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
38
+ // // 默认值为[]
39
+ // default: [],
40
+ // },
41
+ // _categoryList2: {
42
+ // getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
43
+ // // 对象类型 默认值为User类型
44
+ // default: { name: "zhao", age: 20 },
45
+ // },
46
+ // _categoryList3: {
47
+ // getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
48
+ // // 对象类型 默认值可以为null
49
+ // default: null,
50
+ // },
51
+ // },
52
+ // });
@@ -1,14 +1,14 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/_api";
2
2
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
3
3
  import type { IInjectAllData, IInjectMethods, IInjectStore } from "../InstanceInject/instanceConfig";
4
- import type { GetComputedDoc } from "../RootComponent/Computed/GetComputedDoc";
4
+ import type { GetComputedDef } from "../RootComponent/Computed/GetComputedDef";
5
5
  import type { RootComponentInstance } from "../RootComponent/Instance/RootComponentInstance";
6
6
  import type { LifetimesOption } from "../RootComponent/Lifetimes/LifetimesOption";
7
7
  import type { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
8
8
  import type { ObserversOption } from "../RootComponent/Observers/ObserversOption";
9
9
  import type { PageLifetimesOption } from "../RootComponent/PageLifetimes/PageLifetimesOption";
10
10
  import type { RootComponentDefinition } from "../RootComponent/returnType";
11
- import type { GetStoreDoc } from "../RootComponent/Store/GeTStoreDoc";
11
+ import type { GetStoreDef } from "../RootComponent/Store/GetStoreDef";
12
12
  import type { WatchOption } from "../RootComponent/Watch/WatchOption";
13
13
  import type { ChunkComputedConstraint } from "./ChunkComputed/ChunkComputedConstraint";
14
14
  import type { ChunkComputedOption } from "./ChunkComputed/ChunkComputedOption";
@@ -99,9 +99,9 @@ type ChunkComponentConstructor<
99
99
  TMethods extends MethodsConstraint = {},
100
100
  TData extends object = {},
101
101
  StoreDoc extends object = ChunkStoreConstraint<Required<TRootComponentReturnType["properties"]>> extends TStore ? {}
102
- : GetStoreDoc<TStore>,
102
+ : GetStoreDef<TStore>,
103
103
  TComputed extends ChunkComputedConstraint = {},
104
- ComputedDoc extends object = GetComputedDoc<TComputed>,
104
+ ComputedDoc extends object = GetComputedDef<TComputed>,
105
105
  EventsDoc extends object = IfExtends<ChunkEventsConstraint, TEvents, {}, TEvents>,
106
106
  PropertiesDoc extends object = NonNullable<TRootComponentReturnType["properties"]>,
107
107
  >(
@@ -65,17 +65,20 @@ CustomComponent<{}, CompDoc>()({
65
65
  },
66
66
  });
67
67
 
68
- // data建立的类型在setData时为组件类型
68
+ // 确保实例和setData中使用的data字段类型为文档中定义的类型而非data配置中的类型(data中配置的类型可能推导默认为字面量类型,通过加入Replace泛型替换为对应的文档类型。),
69
69
  CustomComponent<{ data: { _num: number } }, CompDoc>()({
70
70
  data: {
71
- aaa_obj: null as Mock_User | null,
71
+ aaa_obj: null, // 类型为null 而非 Mock_User | null
72
+ aaa_str: "a", // 类型为"a" 而非string
73
+ aaa_num: 123, // 类型为123 而非number
72
74
  },
73
75
  lifetimes: {
74
76
  attached() {
77
+ // 实例中的aaa_obj类型为文档中定义的类型 Mock_User | null 而非data配置中的类型 null
75
78
  void Checking<typeof this.data.aaa_obj, Mock_User | null, Test.Pass>;
76
-
79
+ // setData中aaa_str类型为文档中定义的类型 "a" | "b" 而非data配置中的类型 "a"
77
80
  this.setData({
78
- aaa_obj: {} as Mock_User, // aaa_obj 类型为 Mock_User | null 而非 null
81
+ aaa_str: "b",
79
82
  });
80
83
  },
81
84
  },
@@ -1,7 +1,7 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
3
3
  import type { ComputeIntersection, Select } from "hry-types/src/Object/_api";
4
- import type { ComputeObject } from "../../../types/ComputeObj";
4
+ import type { ComputeObject } from "../../../types/ComputeObject";
5
5
  import type { RemovePrefix } from "../../../types/RemovePrefix";
6
6
  import type { Composed } from "../../RootComponent/CustomEvents/CustomEventsTag";
7
7
 
@@ -1,4 +1,5 @@
1
- import type { Getter, WithDefault } from "../../RootComponent/Store/StoreConstraint";
1
+ import type { AddNullForObject } from "../../../types/AddNullForObject";
2
+ import type { Getter } from "../../RootComponent/Store/StoreConstraint";
2
3
 
3
4
  /**
4
5
  * 子组件Data字段约束
@@ -8,5 +9,5 @@ export type CustomStoreConstraint<
8
9
  PropertyDoc extends object,
9
10
  legal extends object,
10
11
  > = {
11
- [k in keyof legal]?: Getter<PropertyDoc, legal[k]> | WithDefault<PropertyDoc, legal[k]>;
12
+ [k in keyof legal]?: Getter<PropertyDoc, AddNullForObject<legal[k]>>;
12
13
  };
@@ -1,6 +1,5 @@
1
1
  import type { G } from "hry-types";
2
2
  import type { Validators } from "../../../types/Validators";
3
- import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
4
3
 
5
4
  export type CustomStoreOption<TStore extends object, legalKeys extends PropertyKey> = {
6
5
  /**
@@ -28,7 +27,6 @@ export type CustomStoreOption<TStore extends object, legalKeys extends PropertyK
28
27
  "",
29
28
  "与inherit和data字段重复或前缀错误"
30
29
  >,
31
- TypeValidator<TStore>,
32
30
  ]
33
31
  >;
34
32
  };
@@ -47,54 +47,14 @@ CustomComponent<{
47
47
  aaa_num: () => 123,
48
48
  },
49
49
  });
50
-
51
- type DocText = ComponentDoc<{
50
+ // 类型约束错误
51
+ CustomComponent<{
52
52
  properties: {
53
- aaa_useList: User[];
53
+ aaa_num: number;
54
54
  };
55
- }>;
56
- type User = {
57
- name: string;
58
- age?: number;
59
- };
60
- type AllGoods = Record<string, User[] | undefined>;
61
- const M_User = observable({
62
- allUser: {
63
- categoryA: [{ name: "zhao", age: 20 }],
64
- categoryB: [{ name: "zhao" }],
65
- } as AllGoods,
66
- });
67
-
68
- CustomComponent<{ properties: { categoryId: string } }, DocText>()({
69
- store: {
70
- // @ts-expect-error 1 响应式包含undefined时 不可以写成getter函数形式
71
- aaa_useList: (data) => M_User.allUser[data.categoryId],
72
- },
73
- });
74
- CustomComponent<{ properties: { categoryId: string } }, DocText>()({
75
- store: {
76
- _aaa_categoryList: {
77
- // @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
78
- getter: (data) => M_User.allUser[data.categoryId] as User[],
79
- default: 0,
80
- },
81
- },
82
- });
83
- CustomComponent<{ properties: { categoryId: string } }, DocText>()({
84
- store: {
85
- _aaa_categoryList1: {
86
- getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
87
- // @ts-expect-error 3 默认值应该为[]
88
- default: 0,
89
- },
90
- },
91
- });
92
- CustomComponent<{ properties: { categoryId: string } }, DocText>()({
55
+ }, DocA>()({
93
56
  store: {
94
- _aaa_categoryList2: {
95
- getter: (data) => M_User.allUser[data.categoryId]?.[0],
96
- // @ts-expect-error 对象类型 默认值为User类型或null namesss错误
97
- default: { namesss: "zhao", age: 20 },
98
- },
57
+ // @ts-expect-error 返回类型错误
58
+ aaa_num: () => undefined,
99
59
  },
100
60
  });
@@ -34,48 +34,3 @@ CustomComponent<{ data: { _num: number } }, DocA, "a">()({
34
34
  aaaA_isReady: () => false,
35
35
  },
36
36
  });
37
-
38
- type DocText = ComponentDoc<{
39
- properties: {
40
- aaa_useList: User[];
41
- };
42
- }>;
43
- type User = {
44
- name: string;
45
- age?: number;
46
- };
47
- type AllGoods = Record<string, User[]>;
48
- const M_User = observable({
49
- allUser: {
50
- categoryA: [{ name: "zhao", age: 20 }],
51
- categoryB: [{ name: "zhao" }],
52
- } as AllGoods,
53
- });
54
-
55
- // store中getter函数第一个参数为properties的类型
56
- CustomComponent<{ properties: { categoryId: string } }, DocText>()({
57
- store: {
58
- // 1 响应式不包含undefined时 只能写成getter函数形式
59
- aaa_useList: (data) => M_User.allUser[data.categoryId],
60
- // 2 响应式数据包含undefined时 只能写成对象形式
61
- _aaa_categoryList: {
62
- getter: (data) => M_User.allUser[data.categoryId][0].age,
63
- default: 0,
64
- },
65
- _aaa_categoryList1: {
66
- getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
67
- // 默认值为[]
68
- default: [],
69
- },
70
- _aaa_categoryList2: {
71
- getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
72
- // 对象类型 默认值为User类型
73
- default: { name: "zhao", age: 20 },
74
- },
75
- _aaa_categoryList3: {
76
- getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
77
- // 对象类型 默认值可以为null
78
- default: null,
79
- },
80
- },
81
- });
@@ -5,12 +5,13 @@ import type { Extra } from "../../types/Extra";
5
5
  import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
6
6
  import type { InnerFields } from "../../types/InnerData";
7
7
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
8
+ import type { Replace } from "../../types/Replace";
8
9
  import type { ReplacePrefix } from "../../types/ReplacePrefix";
9
10
  import type { UnionToComma } from "../../types/UnionToComma.test";
10
11
  import type { ComponentDoc } from "../DefineComponent/returnType/ComponentDoc";
11
12
  import type { IInjectStore } from "../InstanceInject/instanceConfig";
12
13
  import type { RootComponentDefinition } from "../RootComponent/returnType";
13
- import type { GetStoreDoc } from "../RootComponent/Store/GeTStoreDoc";
14
+ import type { GetStoreDef } from "../RootComponent/Store/GetStoreDef";
14
15
  import type { CustomComputedConstraint } from "./CustomComputed/CustomComputedConstraint";
15
16
  import type { CustomComputedOption } from "./CustomComputed/CustomComputedOption";
16
17
  import type { GetCustomComputedDoc } from "./CustomComputed/GetCustomComputedDoc";
@@ -149,10 +150,10 @@ type Options<
149
150
  & ThisType<
150
151
  CustomInstance<
151
152
  SubMethodsDoc & RootDoc["methods"],
152
- // Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>,// 解除Replace的约束
153
- SubDataDoc,
154
- // AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, // 解除Replace的约束
155
- AllRootDataDoc & SubDataDoc & SubComputedDoc & SubStoreDoc,
153
+ Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, // Replace目的是让setData中的类型与文档中定义的类型一致
154
+ // SubDataDoc,
155
+ AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, // Replace的目的是让实例中的类型与文档中定义的类型一致
156
+ // AllRootDataDoc & SubDataDoc & SubComputedDoc & SubStoreDoc,
156
157
  NonNullable<RootDoc["customEvents"]>,
157
158
  SubStoreDoc
158
159
  >
@@ -223,7 +224,7 @@ type CustomComponentConstructor<
223
224
  >,
224
225
  TStore,
225
226
  {},
226
- GetStoreDoc<TStore>
227
+ GetStoreDef<TStore>
227
228
  >,
228
229
  // 无效的计算
229
230
  ComputedDoc extends object = IfExtends<
@@ -1,4 +1,4 @@
1
- import { Checking, type Test } from "hry-types";
1
+ import { typeEqual } from "../../../../utils/typeEqual";
2
2
  import type { CustomComponentDefinition } from "../../../CustomComponent/returnType";
3
3
  import type { Bubbles, Composed } from "../../../RootComponent/CustomEvents/CustomEventsTag";
4
4
  import { DefineComponent } from "../..";
@@ -1039,11 +1039,11 @@ const aaa = DefineComponent({
1039
1039
  A,
1040
1040
  ],
1041
1041
  });
1042
- void aaa;
1043
- void Checking<typeof aaa, {
1042
+ type Epected = {
1044
1043
  events: {
1045
1044
  test_a: string | number | boolean | Composed;
1046
1045
  test_b: string | number | Composed;
1047
1046
  test_c: boolean | Composed;
1048
1047
  };
1049
- }, Test.Pass>;
1048
+ };
1049
+ typeEqual<Epected>(aaa);
@@ -27,7 +27,7 @@ type Constructor = <
27
27
  TPath extends Path = "/",
28
28
  >(
29
29
  options: Options<TRootComponentDefinition, TCustomComponentDefinitionList, TName, TPath>,
30
- ) => // 根据是否传入name字段来区分生成页面文档还是组件文档。
30
+ ) => // 根据是否传入name字段(当isPage不为true时,类型约束name不为空字符串)来区分生成页面文档还是组件文档。
31
31
  IfExtends<
32
32
  "",
33
33
  TName,
@@ -45,14 +45,14 @@ export type DefineComponentOptionRuntime = {
45
45
  };
46
46
 
47
47
  /**
48
- * DefineComponent是构建组件的核心API,在annil架构中,所有组件(页面组件和自定义组件)都通过它来构建的。
49
- * 它返回的类型可能是页面文档(`PageDoc`)或者自定义组件文档(`ComponentDoc`),具体取决于传入的选项中是否包含`name`字段。
48
+ * DefineComponent是构建组件的核心API,所有组件(页面组件和自定义组件)都通过它来构建的。
49
+ * 它返回的类型可能是页面文档(`PageDoc`)或者自定义组件文档(`ComponentDoc`),具体取决于传入rootComponent中isPage的值。
50
50
  * 它的作用是把根组件定义(`RootComponentDefinition`)和子组件定义(`CustomComponentDefinition`和`ChunkComponentDefinition`)整合成原生`Component`的选项配置,最终通过原生`Component`来构建组件。
51
51
  */
52
52
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- 返回类型由Constructor定义,实现无需。
53
53
  export const DefineComponent: Constructor = function(options): any {
54
54
  Component(
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Options泛型中properties字段类型与WechatMiniprogram.Component.Constructor中的properties字段类型不兼容,但运行时是兼容的,所以这里使用any断言。
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Options泛型中properties字段类型与WechatMiniprogram.Component.Constructor中的properties字段类型不兼容,但运行时是兼容的,所以这里使用any
56
56
  normalizeOptions(options as DefineComponentOptionRuntime) as any,
57
57
  );
58
58
  };
@@ -1,9 +1,6 @@
1
1
  import type mobx from "mobx";
2
2
  import type { Instance } from "../../../RootComponent/Instance/RootComponentInstance";
3
- import type { Getter, StoreConstraint, WithDefault } from "../../../RootComponent/Store/StoreConstraint";
4
- function isGetter(value: Getter | WithDefault): value is Getter {
5
- return typeof value === "function";
6
- }
3
+ import type { StoreConstraint } from "../../../RootComponent/Store/StoreConstraint";
7
4
  export function reactionRegister(this: Instance, storeConfig: StoreConstraint) {
8
5
  // eslint-disable-next-line @typescript-eslint/no-require-imports
9
6
  const { comparer, reaction, toJS } = require("mobx") as typeof mobx;
@@ -11,23 +8,11 @@ export function reactionRegister(this: Instance, storeConfig: StoreConstraint) {
11
8
  this.disposer = {};
12
9
  const peddingSetData: Record<string, unknown> = {};
13
10
  for (const key in storeConfig) {
14
- let value;
15
- let getter;
16
- const itemConfig = storeConfig[key];
17
- if (isGetter(itemConfig)) {
18
- value = itemConfig(this.data);
19
- if (value === undefined) {
20
- throw new Error(`store配置中 ${key} 字段的 函数值不可为undefined`);
21
- }
22
- getter = itemConfig;
23
- } else {
24
- if (itemConfig.getter(this.data) !== undefined) {
25
- throw new Error(`store配置中 ${key}字段的配置对象中getter函数值不为undefined`);
26
- }
27
- getter = itemConfig.getter;
28
- value = itemConfig.default;
11
+ const getter = storeConfig[key];
12
+ const value = getter(this.data);
13
+ if (value === undefined) {
14
+ throw new Error(`store配置中 ${key} 字段的返回值不可为undefined`);
29
15
  }
30
-
31
16
  // 添加响应式逻辑
32
17
  peddingSetData[key] = toJS(value);
33
18
  this.disposer[key] = reaction(
@@ -19,7 +19,6 @@ const OnlyPropsRootDoc = RootComponent()({
19
19
  value: null,
20
20
  },
21
21
  },
22
- customEvents: {}, // EmptyObject
23
22
  });
24
23
 
25
24
  const compDocOnlyProperties = DefineComponent({
@@ -5,10 +5,9 @@ import type { ComputedConstraint } from "./ComputedConstraint";
5
5
  export type ComputedOption<
6
6
  TComputed extends ComputedConstraint,
7
7
  CompareKeys extends PropertyKey,
8
- > // Instance extends object,
9
- = {
8
+ > = {
10
9
  /**
11
- * computed字段, [类型约束ComputedConstraint](ComputedConstraint.ts)
10
+ * computed字段
12
11
  * @remarks
13
12
  *
14
13
  * 函数体内,可通过this.data获取实例其他数据(依赖),setData发生时,若数据(依赖)发生变化则重新运行函数体并setData。
@@ -5,6 +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 GetComputedDef<TComputed extends ComputedConstraint> = {
9
9
  [k in keyof TComputed]: ReturnType<TComputed[k]>;
10
10
  };