annil 1.1.1 → 1.2.0-beta.0

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 (164) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +2 -2
  3. package/dist/api/DefineComponent/collectOptionsForComponent.js +24 -28
  4. package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
  5. package/dist/api/DefineComponent/index.d.ts +12 -12
  6. package/dist/api/DefineComponent/index.js.map +1 -1
  7. package/dist/api/RootComponent/Computed/ComputedOption.d.ts +2 -2
  8. package/dist/api/RootComponent/Computed/GetComputedDoc.d.ts +2 -2
  9. package/dist/api/RootComponent/Computed/test/normal.test.js +5 -12
  10. package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
  11. package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +2 -2
  12. package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -1
  13. package/dist/api/RootComponent/Data/DataOption.d.ts +2 -2
  14. package/dist/api/RootComponent/Data/GetDataDoc.d.ts +1 -4
  15. package/dist/api/RootComponent/Data/test/GetDataDoc.test.d.ts +3 -2
  16. package/dist/api/RootComponent/Data/test/GetDataDoc.test.js +5 -5
  17. package/dist/api/RootComponent/Data/test/GetDataDoc.test.js.map +1 -1
  18. package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
  19. package/dist/api/RootComponent/Events/EventsConstraint.d.ts +6 -5
  20. package/dist/api/RootComponent/Events/EventsOption.d.ts +2 -3
  21. package/dist/api/RootComponent/Events/test/normal.test.js +1 -1
  22. package/dist/api/RootComponent/Events/test/normal.test.js.map +1 -1
  23. package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +5 -4
  24. package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
  25. package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +6 -7
  26. package/dist/api/RootComponent/PageLifetimes/test/error.test.js +3 -1
  27. package/dist/api/RootComponent/PageLifetimes/test/error.test.js.map +1 -1
  28. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js +3 -1
  29. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
  30. package/dist/api/RootComponent/RootComponentDoc.d.ts +17 -3
  31. package/dist/api/RootComponent/Store/GeTStoreDoc.d.ts +1 -1
  32. package/dist/api/RootComponent/Store/StoreOption.d.ts +2 -2
  33. package/dist/api/RootComponent/Store/test/normal.test.js.map +1 -1
  34. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +0 -2
  35. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
  36. package/dist/api/RootComponent/index.d.ts +9 -10
  37. package/dist/api/RootComponent/index.js.map +1 -1
  38. package/dist/api/SubComponent/SubData/SubDataConstraint.d.ts +2 -2
  39. package/dist/api/SubComponent/SubData/test/normal.test.js +0 -15
  40. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  41. package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
  42. package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +2 -2
  43. package/dist/api/SubComponent/SubEvents/test/error.test.js.map +1 -1
  44. package/dist/api/SubComponent/SubEvents/test/normal.test.js +20 -0
  45. package/dist/api/SubComponent/SubEvents/test/normal.test.js.map +1 -1
  46. package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +3 -2
  47. package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +3 -0
  48. package/dist/api/SubComponent/SubInherit/SubInheritOption.js +2 -0
  49. package/dist/api/SubComponent/SubInherit/SubInheritOption.js.map +1 -0
  50. package/dist/api/SubComponent/SubInherit/test/error.test.js +1 -1
  51. package/dist/api/SubComponent/SubInherit/test/error.test.js.map +1 -1
  52. package/dist/api/SubComponent/SubInherit/test/normal.test.js.map +1 -1
  53. package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +3 -2
  54. package/dist/api/SubComponent/SubMethods/test/error.test.js +6 -0
  55. package/dist/api/SubComponent/SubMethods/test/error.test.js.map +1 -1
  56. package/dist/api/SubComponent/SubMethods/test/normarl.test.js +3 -3
  57. package/dist/api/SubComponent/SubMethods/test/normarl.test.js.map +1 -1
  58. package/dist/api/SubComponent/SubPageLifetimes/SubPageLifetimesOption.d.ts +1 -1
  59. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.d.ts +0 -1
  60. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js +1 -11
  61. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js.map +1 -1
  62. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.d.ts +0 -1
  63. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js +1 -25
  64. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
  65. package/dist/api/SubComponent/SubStore/SubDataConstraint.d.ts +2 -2
  66. package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +1 -1
  67. package/dist/api/SubComponent/SubStore/test/error.test.js +2 -0
  68. package/dist/api/SubComponent/SubStore/test/error.test.js.map +1 -1
  69. package/dist/api/SubComponent/SubStore/test/normal.test.js +1 -0
  70. package/dist/api/SubComponent/SubStore/test/normal.test.js.map +1 -1
  71. package/dist/api/SubComponent/SubWatch/SubWatchOption.d.ts +2 -1
  72. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.d.ts +1 -0
  73. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js +44 -1
  74. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js.map +1 -1
  75. package/dist/api/SubComponent/SubWatch/test/error.test.js +10 -2
  76. package/dist/api/SubComponent/SubWatch/test/error.test.js.map +1 -1
  77. package/dist/api/SubComponent/index.d.ts +19 -13
  78. package/dist/api/SubComponent/index.js.map +1 -1
  79. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  80. package/dist/behaviors/BComputedAndWatch/types.d.ts +1 -0
  81. package/dist/behaviors/BStore.js.map +1 -1
  82. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  83. package/dist/index.d.ts +3 -3
  84. package/dist/index.js +1 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/types/OfficialTypeAlias.d.ts +1 -1
  87. package/dist/types/RemoveInnerData.d.ts +1 -0
  88. package/dist/types/RemoveInnerData.js +2 -0
  89. package/dist/types/RemoveInnerData.js.map +1 -0
  90. package/dist/utils/InnerMarker.js +1 -1
  91. package/dist/utils/InnerMarker.js.map +1 -1
  92. package/dist/utils/deepClone.js.map +1 -1
  93. package/package.json +4 -2
  94. package/src/api/DefineComponent/collectOptionsForComponent.ts +176 -66
  95. package/src/api/DefineComponent/index.ts +13 -9
  96. package/src/api/RootComponent/Computed/ComputedOption.ts +23 -3
  97. package/src/api/RootComponent/Computed/GetComputedDoc.ts +1 -3
  98. package/src/api/RootComponent/Computed/test/normal.test.ts +9 -19
  99. package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +26 -22
  100. package/src/api/RootComponent/CustomEvents/test/error.test.ts +5 -5
  101. package/src/api/RootComponent/CustomEvents/test/normal.test.ts +1 -1
  102. package/src/api/RootComponent/Data/DataConstraint.ts +1 -1
  103. package/src/api/RootComponent/Data/DataOption.ts +6 -4
  104. package/src/api/RootComponent/Data/GetDataDoc.ts +1 -18
  105. package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +14 -25
  106. package/src/api/RootComponent/Data/test/error.test.ts +2 -2
  107. package/src/api/RootComponent/Data/test/normal.test.ts +5 -8
  108. package/src/api/RootComponent/Events/EventsConstraint.ts +24 -19
  109. package/src/api/RootComponent/Events/EventsOption.ts +54 -6
  110. package/src/api/RootComponent/Events/test/normal.test.ts +16 -16
  111. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +1 -1
  112. package/src/api/RootComponent/IsPage/IsPageOption.ts +1 -1
  113. package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +11 -8
  114. package/src/api/RootComponent/Lifetimes/LifetimesOption.ts +26 -0
  115. package/src/api/RootComponent/Lifetimes/test/error.test.ts +3 -13
  116. package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
  117. package/src/api/RootComponent/Methods/MethodsOption.ts +3 -0
  118. package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +21 -10
  119. package/src/api/RootComponent/PageLifetimes/test/error.test.ts +7 -5
  120. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +9 -10
  121. package/src/api/RootComponent/Properties/PropertiesOption.ts +19 -32
  122. package/src/api/RootComponent/RootComponentDoc.ts +19 -3
  123. package/src/api/RootComponent/Store/GeTStoreDoc.ts +1 -1
  124. package/src/api/RootComponent/Store/StoreOption.ts +14 -2
  125. package/src/api/RootComponent/Store/test/error.test.ts +5 -5
  126. package/src/api/RootComponent/Store/test/normal.test.ts +1 -0
  127. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +1 -12
  128. package/src/api/RootComponent/index.ts +20 -19
  129. package/src/api/SubComponent/SubComputed/SubComputedOption.ts +0 -1
  130. package/src/api/SubComponent/SubData/SubDataConstraint.ts +2 -3
  131. package/src/api/SubComponent/SubData/SubDataOption.ts +4 -0
  132. package/src/api/SubComponent/SubData/test/error.test.ts +1 -1
  133. package/src/api/SubComponent/SubData/test/normal.test.ts +6 -37
  134. package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +7 -2
  135. package/src/api/SubComponent/SubEvents/SubEventsOptions.ts +7 -2
  136. package/src/api/SubComponent/SubEvents/test/error.test.ts +5 -4
  137. package/src/api/SubComponent/SubEvents/test/normal.test.ts +31 -4
  138. package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +6 -3
  139. package/src/api/SubComponent/SubInherit/SubInheritOption.ts +8 -0
  140. package/src/api/SubComponent/SubInherit/test/error.test.ts +9 -7
  141. package/src/api/SubComponent/SubInherit/test/normal.test.ts +5 -4
  142. package/src/api/SubComponent/SubMethods/SubMethodsOption.ts +7 -3
  143. package/src/api/SubComponent/SubMethods/test/error.test.ts +13 -5
  144. package/src/api/SubComponent/SubMethods/test/normarl.test.ts +6 -12
  145. package/src/api/SubComponent/SubPageLifetimes/SubPageLifetimesOption.ts +2 -2
  146. package/src/api/SubComponent/SubPageLifetimes/test/error.test.ts +1 -32
  147. package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +1 -74
  148. package/src/api/SubComponent/SubStore/SubDataConstraint.ts +2 -2
  149. package/src/api/SubComponent/SubStore/SubStoreOption.ts +15 -1
  150. package/src/api/SubComponent/SubStore/test/error.test.ts +4 -0
  151. package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -0
  152. package/src/api/SubComponent/SubWatch/SubWatchOption.ts +2 -1
  153. package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +75 -43
  154. package/src/api/SubComponent/SubWatch/test/error.test.ts +12 -3
  155. package/src/api/SubComponent/index.ts +28 -17
  156. package/src/behaviors/BComputedAndWatch/index.ts +2 -2
  157. package/src/behaviors/BComputedAndWatch/types.ts +1 -0
  158. package/src/behaviors/BStore.ts +4 -6
  159. package/src/behaviors/BbeforeCreated.ts +2 -2
  160. package/src/index.ts +12 -8
  161. package/src/types/OfficialTypeAlias.ts +7 -11
  162. package/src/types/RemoveInnerData.ts +5 -0
  163. package/src/utils/InnerMarker.ts +1 -1
  164. package/src/utils/deepClone.ts +1 -0
@@ -1,6 +1,7 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { Wm } from "../../../../thirdLib";
3
- import type { Detail, WMBaseEvent } from "../../../../types/OfficialTypeAlias";
3
+
4
+ import type { Detail, Mark, WMBaseEvent } from "../../../..";
4
5
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
5
6
  import type {
6
7
  Bubbles,
@@ -10,6 +11,7 @@ import type {
10
11
  Capture,
11
12
  CaptureComposed,
12
13
  } from "../../../RootComponent/CustomEvents/CustomEventsTag";
14
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
13
15
  import { SubComponent } from "../..";
14
16
 
15
17
  type CompDoc = ComponentDoc<{
@@ -51,13 +53,13 @@ const sub1 = SubComponent<{}, CompDoc>()({
51
53
  },
52
54
  });
53
55
 
54
- // 1.2 Composed事件会被返回
55
56
  type Sub1Expected = {
56
57
  BubblesComposed: string | BubblesComposed;
57
58
  CapturePhaseComposed: string | CaptureComposed;
58
59
  BubblesCapturePhaseComposed: string | BubblesCaptureComposed;
59
60
  };
60
61
 
62
+ // 1.2 Composed事件会被返回
61
63
  Checking<typeof sub1, Sub1Expected, Test.Pass>;
62
64
 
63
65
  // 2.1 key可写入后缀字段(_catch,表示阻止冒泡和捕获事件)。
@@ -75,7 +77,6 @@ const sub2 = SubComponent<{}, CompDoc>()({
75
77
  // 2.2 返回没有被加后最(_catch)的Composed事件
76
78
  Checking<typeof sub2, { BubblesCapturePhaseComposed: string | BubblesCaptureComposed }, Test.Pass>;
77
79
 
78
- // 2.3 key可写入后缀字段(_catch,表示阻止冒泡和捕获事件)。
79
80
  const sub3 = SubComponent<{}, CompDoc>()({
80
81
  events: {
81
82
  aaa_BubblesComposed_catch(e) {
@@ -106,7 +107,7 @@ SubComponent<{}, Wm.View>()({
106
107
  },
107
108
  });
108
109
 
109
- // 3.2 基础组件自定义事件参数为Detail<object>
110
+ // 3.1 基础组件自定义事件参数为Detail<object>
110
111
  SubComponent<{}, Wm.ScrollView>()({
111
112
  events: {
112
113
  scrollView_bindscroll(e) {
@@ -126,3 +127,29 @@ SubComponent<{}, Wm.ScrollView>()({
126
127
  // ...
127
128
  },
128
129
  });
130
+
131
+ // 4 可为事件自定义类型
132
+ SubComponent<{}, Wm.View>()({
133
+ events: {
134
+ view_tap(e: Detail<number>) {
135
+ Checking<typeof e.detail, number, Test.Pass>;
136
+ },
137
+ view_longtap(e: Mark<Mock_User>) {
138
+ Checking<typeof e.mark, Mock_User, Test.Pass>;
139
+ },
140
+ // ...
141
+ },
142
+ });
143
+
144
+ // 4 可为事件自定义类型
145
+ SubComponent<{}, Wm.View>()({
146
+ events: {
147
+ view_tap(e: Detail<number>) {
148
+ Checking<typeof e.detail, number, Test.Pass>;
149
+ },
150
+ view_longtap(e: Mark<Mock_User>) {
151
+ Checking<typeof e.mark, Mock_User, Test.Pass>;
152
+ },
153
+ // ...
154
+ },
155
+ });
@@ -1,12 +1,15 @@
1
1
  import type { SelectKeys } from "hry-types/src/Object/_api";
2
+ import type { RemoveInnerData } from "../../../types/RemoveInnerData";
2
3
  import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
3
4
 
4
5
  type WXMLSign = "wxml";
5
6
 
6
7
  /**
7
- * 子组件inherit字段约束,
8
+ * 子组件inherit字段约束,key为子组件所需key,根组件数据的key或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
8
9
  * @returns object
9
10
  */
10
- export type InheritConstraint<RootData extends object, TComponentDoc extends ComponentDoc> = {
11
- [k in keyof TComponentDoc["properties"]]?: SelectKeys<RootData, TComponentDoc["properties"][k]> | WXMLSign;
11
+ export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentDoc> = {
12
+ [k in keyof TComponentDoc["properties"]]?:
13
+ | RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>
14
+ | WXMLSign;
12
15
  };
@@ -0,0 +1,8 @@
1
+ export type SubInheritOption<TInherit> = {
2
+ /**
3
+ * 继承来自根组件的数据(key)或'wxml',wxml表示数据来自`.wxml`文件(例如数据来自父元素循环wx:for的数据).
4
+ * inherit字段最终会在选项中删除,它的存在是为了ts开发时提供心智模型(类型检测),js开发好比注释功能.便于代码阅读。
5
+ * 带类型检测
6
+ */
7
+ inherit?: TInherit;
8
+ };
@@ -17,6 +17,8 @@ type Mock_RootDoc = RootComponentDoc<{
17
17
  str: string;
18
18
  literal_str: "a" | "b" | "c";
19
19
  bool: boolean;
20
+ _num: number;
21
+ _str: string;
20
22
  };
21
23
  computed: {
22
24
  Cuinon: string | boolean;
@@ -34,19 +36,19 @@ type Mock_CompDoc = ComponentDoc<{
34
36
  };
35
37
  }>;
36
38
 
37
- // RootDoc不为空时,可继承对应类型的字段。
39
+ // 1 继承字段类型错误
38
40
  SubComponent<Mock_RootDoc, Mock_CompDoc>()({
39
41
  inherit: {
40
- // @ts-expect-error [string | number] 不是 [number] 的子集
42
+ // @ts-expect-error 1.1 [string | number] 不是 [number] 的子集
41
43
  aaa_num: "unionStrNum",
42
- // @ts-expect-error [123 | 456 | 789] 不是 [123 | 456] 的子集
44
+ // @ts-expect-error 1.2 [123 | 456 | 789] 不是 [123 | 456] 的子集
43
45
  aaa_literal_num: "optional_literal_num",
44
- // @ts-expect-error [string | number] 不是 [string] 的子集
45
- aaa_str: "" as "unionStrNum",
46
+ // @ts-expect-error 1.3 不可继承内部字段
47
+ aaa_str: "_str",
46
48
  },
47
49
  });
48
50
 
49
- // inherit字段最终不会在组件配置中,意义在于通过声明继承字段便于类型判断,配置是否满足组件的需求。下面示例中,配置不满足组件需求,Mock_CompDoc需要一些必传字段没有配置,即使这些字段存在在于根组件(或wmxl).而返回的字符串(错误),无法通过DefinedComponent Api 类型检测。
51
+ // 2 inherit字段最终不会在组件配置中,意义在于通过声明继承字段便于类型判断,配置是否满足子组件文档的需求。下面示例中,配置不满足组件需求,Mock_CompDoc需要一些必传字段没有配置,即使这些字段存在在于根组件(或wmxl).而返回的字符串(错误),无法通过DefinedComponent Api 类型检测。
50
52
  const subDoc = SubComponent<Mock_RootDoc, Mock_CompDoc>()({
51
53
  data: {
52
54
  aaa_num: 123,
@@ -57,6 +59,6 @@ Checking<typeof subDoc, SubComponentDoc, Test.Fail>;
57
59
 
58
60
  DefineComponent({
59
61
  name: "xxx",
60
- // @ts-expect-error 不能将类型“string”分配给类型“_SubComponentDoc”。
62
+ // @ts-expect-error 2 不能将类型“string”分配给类型“_SubComponentDoc”。
61
63
  subComponents: [subDoc],
62
64
  });
@@ -2,13 +2,16 @@ import type { ComponentDoc } from "../../../DefineComponent/ReturnType/Component
2
2
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
3
3
  import { SubComponent } from "../..";
4
4
 
5
+ /**
6
+ * inherit字段最终会在选项中删除,它用ts开发类型检测。
7
+ */
5
8
  type Mock_RootDoc = RootComponentDoc<{
6
9
  properties: {
7
10
  required_num: number;
8
11
  optional_literal_num?: 123 | 456 | 789;
9
12
  unionStrNum: string | number;
10
13
  required_obj: object | null;
11
- optional_obj?: object;
14
+ optional_obj?: object | null;
12
15
  };
13
16
  data: {
14
17
  str: string;
@@ -31,7 +34,7 @@ type Mock_CompDoc = ComponentDoc<{
31
34
  };
32
35
  }>;
33
36
 
34
- // 1 没有可继承的数据,类型可为'wxml',表示数据来自wxml(例如数据来自父组件循环wx:for后的数据等情况)
37
+ // 1 没有可继承的数据,类型可为'wxml',表示数据来自wxml(例如数据来自父元素循环wx:for后的数据等情况)
35
38
  SubComponent<{}, Mock_CompDoc>()({
36
39
  inherit: {
37
40
  aaa_num: "wxml",
@@ -51,5 +54,3 @@ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
51
54
  aaa_obj1: "" as "required_obj" | "optional_obj" | "wxml",
52
55
  },
53
56
  });
54
-
55
- // inherit字段最终会在配置对象中删除,它用类型检测。
@@ -1,13 +1,17 @@
1
1
  import type { V } from "hry-types";
2
2
  import type { PrefixValidator } from "hry-types/src/Generic/PrefixValidator";
3
+ import type { SubMethodsConstraint } from "./SubMethodsConstraint";
3
4
 
4
5
  export type SubMethodsOption<
5
- TSubMethods extends object,
6
+ TSubMethods extends SubMethodsConstraint,
6
7
  TPrefix extends string,
7
- CompCustomEventsKeys extends PropertyKey,
8
+ ExcludedKeys extends PropertyKey,
8
9
  > = {
10
+ /**
11
+ * 前缀检测和重复检测(与events和组件customEvents字段)
12
+ */
9
13
  methods?:
10
14
  & TSubMethods
11
15
  & PrefixValidator<TSubMethods, TPrefix>
12
- & V.DuplicateFieldValidator<TSubMethods, CompCustomEventsKeys>;
16
+ & V.DuplicateFieldValidator<TSubMethods, ExcludedKeys>;
13
17
  };
@@ -1,4 +1,5 @@
1
1
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
+ import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
2
3
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
3
4
  import { SubComponent } from "../..";
4
5
 
@@ -16,22 +17,29 @@ type RootDoc = RootComponentDoc<{
16
17
 
17
18
  type CompDoc = ComponentDoc<{
18
19
  customEvents: {
19
- aaa_str: string;
20
+ aaa_str: string | Bubbles;
20
21
  };
21
22
  }>;
22
23
 
23
- // 前缀错误
24
+ // 1 前缀错误
24
25
  SubComponent<RootDoc, CompDoc>()({
25
26
  methods: {
26
- // @ts-expect-error 前缀错误
27
+ // @ts-expect-error 1.1 前缀错误
27
28
  xxx_yyy() {},
28
29
  },
29
30
  });
30
31
 
31
- // 与组件事件字段重复
32
+ // 2 重复检测
32
33
  SubComponent<RootDoc, CompDoc>()({
34
+ events: {
35
+ aaa_str_catch() {
36
+ },
37
+ },
33
38
  methods: {
34
- // @ts-expect-error 与组件事件字段重复
39
+ // @ts-expect-error 2.1 与组件自定义事件字段重复
35
40
  aaa_str() {},
41
+ // @ts-expect-error 2.2 与events字段重复
42
+ aaa_str_catch() {
43
+ },
36
44
  },
37
45
  });
@@ -6,12 +6,6 @@ type RootDoc = RootComponentDoc<{
6
6
  methods: {
7
7
  Mstr: () => string;
8
8
  };
9
- events: {
10
- Estr: () => string;
11
- };
12
- customEvents: {
13
- Cstr: string;
14
- };
15
9
  }>;
16
10
 
17
11
  type CompDoc = ComponentDoc<{
@@ -20,12 +14,7 @@ type CompDoc = ComponentDoc<{
20
14
  };
21
15
  }>;
22
16
 
23
- // 默认可以为{}。
24
- SubComponent<RootDoc, CompDoc>()({
25
- methods: {},
26
- });
27
-
28
- // methods字段可以写 任意字段函数,不与RootDoc和CompDoc中的方法字段重复即可,前缀为CompDoc的前缀
17
+ // methods字段同组件前缀
29
18
  SubComponent<RootDoc, CompDoc>()({
30
19
  methods: {
31
20
  aaa_xxx() {},
@@ -33,3 +22,8 @@ SubComponent<RootDoc, CompDoc>()({
33
22
  // ...
34
23
  },
35
24
  });
25
+
26
+ // 2 默认可以为{}。
27
+ SubComponent<RootDoc, CompDoc>()({
28
+ methods: {},
29
+ });
@@ -1,6 +1,6 @@
1
1
  import type { PageLifetimesOption } from "../../RootComponent/PageLifetimes/PageLifetimesOption";
2
2
 
3
- export type SubPageLifetimesOption<TIsPage extends boolean, AllPropertiesDoc extends object> = PageLifetimesOption<
3
+ export type SubPageLifetimesOption<TIsPage extends boolean, PropertiesDoc extends object> = PageLifetimesOption<
4
4
  TIsPage,
5
- AllPropertiesDoc
5
+ PropertiesDoc
6
6
  >;
@@ -1,32 +1 @@
1
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
2
- import { SubComponent } from "../..";
3
-
4
- type RootDocCompPage = RootComponentDoc<{
5
- isPage: true;
6
- }>;
7
-
8
- type CompDoc = RootComponentDoc<{
9
- properties: {
10
- aaa_str: string;
11
- };
12
- }>;
13
-
14
- /**
15
- * 测试 组件时
16
- */
17
- SubComponent<{}, CompDoc>()({
18
- pageLifetimes: {
19
- // @ts-expect-error 不存在的字段 show是正确字段
20
- onShow() {},
21
- },
22
- });
23
-
24
- /**
25
- * 页面时
26
- */
27
- SubComponent<RootDocCompPage, CompDoc>()({
28
- pageLifetimes: {
29
- // @ts-expect-error 不存在的字段 多了一个 `d`
30
- onLoadd() {},
31
- },
32
- });
1
+ // RootComponent的PageLifetimes
@@ -1,74 +1 @@
1
- import { Checking, type Test } from "hry-types";
2
-
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 RootDocComp = RootComponentDoc<{
8
- properties: {
9
- union?: Mock_User;
10
- optionalObject?: Mock_User | null;
11
- str: string;
12
- obj: object | null;
13
- };
14
- }>;
15
-
16
- type RootDocCompPage = RootComponentDoc<{
17
- isPage: true;
18
- properties: {
19
- union?: Mock_User;
20
- optionalObject?: Mock_User | null;
21
- str: string;
22
- obj: object | null;
23
- };
24
- }>;
25
-
26
- type CompDoc = RootComponentDoc<{
27
- properties: {
28
- aaa_str: string;
29
- };
30
- customEvents: {
31
- aaa_num: number;
32
- };
33
- }>;
34
-
35
- /**
36
- * 测试 组件时
37
- */
38
- SubComponent<RootDocComp, CompDoc>()({
39
- pageLifetimes: {
40
- hide() {},
41
- load() {},
42
- resize(size) {
43
- Checking<typeof size, WechatMiniprogram.Page.IResizeOption, Test.Pass>;
44
- },
45
- show() {},
46
- },
47
- });
48
-
49
- /**
50
- * 页面时
51
- */
52
- SubComponent<RootDocCompPage, CompDoc>()({
53
- pageLifetimes: {
54
- onLoad(props) {
55
- // 接受的必传properties字段,不应该有null
56
- Checking<
57
- typeof props,
58
- {
59
- str: string;
60
- obj: object;
61
- union: Mock_User;
62
- optionalObject: Mock_User | null;
63
- },
64
- Test.Pass
65
- >;
66
- },
67
- onHide() {
68
- console.log("onHide");
69
- },
70
- onResize(options) {
71
- console.log("onResize", options);
72
- },
73
- },
74
- });
1
+ // RootComponent的PageLifetimes
@@ -3,7 +3,7 @@
3
3
  * @returns 当剩余对象不为空对象,约束对象的key为剩余key,类型为剩余key对应的文档类型或函数返回类型。
4
4
  */
5
5
  export type SubStoreConstraint<
6
- O extends object,
6
+ legal extends object,
7
7
  > = {
8
- [k in keyof O]?: () => O[k];
8
+ [k in keyof legal]?: () => legal[k];
9
9
  };
@@ -1,6 +1,20 @@
1
1
  import type { V } from "hry-types";
2
2
 
3
3
  export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
4
+ /**
5
+ * 全局响应式数据字段,全局store对应数据变化实例对应数据自动setData。
6
+ * 约束为组件properties字段去除inherit和data的剩余字段和内部字段
7
+ * 有非法字段(除了约束字段外的字段)检测
8
+ * @example
9
+ * ```ts
10
+ * {
11
+ * //...
12
+ * store: {
13
+ * aaa_str: () => sroreX.str,
14
+ * },
15
+ * }
16
+ * ```
17
+ */
4
18
  store?:
5
19
  & TSubStore
6
20
  & V.IllegalFieldValidator<
@@ -8,6 +22,6 @@ export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyK
8
22
  legalKeys | `_${TPrefix}_${string}`,
9
23
  0,
10
24
  "",
11
- "⚠️ 子组件无需此字段或为字段重复 ⚠️"
25
+ "与inherit和data字段重复或前缀错误"
12
26
  >;
13
27
  };
@@ -31,5 +31,9 @@ SubComponent<{
31
31
  aaa_str: () => user.name,
32
32
  // @ts-expect-error 2 与 data 字段重复
33
33
  aaa_num: () => user.age,
34
+ // @ts-expect-error 3 内部字段前缀错误
35
+ _num: () => user.age,
36
+ // @ts-expect-error 4 超出约束字段
37
+ num: () => user.age,
34
38
  },
35
39
  });
@@ -19,5 +19,7 @@ SubComponent<{}, DocA>()({
19
19
  aaa_str: () => user.name,
20
20
 
21
21
  aaa_num: () => user.age,
22
+ // 运行内部字段(暂定)
23
+ _aaa_ddd: () => user.age,
22
24
  },
23
25
  });
@@ -1,3 +1,4 @@
1
+ import type { NoInfer } from "hry-types/src/Generic/NoInfer";
1
2
  import type { WatchOption } from "../../RootComponent/Watch/WatchOption";
2
3
 
3
- export type SubWatchOption<TWatchData extends object> = WatchOption<TWatchData>;
4
+ export type SubWatchOption<TWatchData extends object> = WatchOption<NoInfer<TWatchData>>;
@@ -1,46 +1,78 @@
1
- // import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
- // import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
3
- // import type { RootComponentDoc } from "../../../RootComponent/RetrunType/RootComponentDoc";
4
-
5
- // type RootDoc = RootComponentDoc<{
6
- // properties: {
7
- // Pnum: number;
8
- // obj: Mock_User | null;
9
- // };
10
- // }>;
11
-
12
- // type CompDoc = ComponentDoc<{
13
- // properties: {
14
- // aaa_str: string;
15
- // aaa_num: number;
16
- // };
17
- // }>;
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
+ obj: Mock_User | null;
10
+ };
11
+ data: {
12
+ num: number;
13
+ };
14
+ store: {
15
+ bool: boolean;
16
+ };
17
+ }>;
18
+
19
+ type CompDoc = ComponentDoc<{
20
+ properties: {
21
+ aaa_obj: Mock_User | null;
22
+ aaa_str: string;
23
+ aaa_num: number;
24
+ aaa_bool: boolean;
25
+ };
26
+ }>;
18
27
 
19
28
  /**
20
- * 测试 computed字段时需要手写类型,可悬停鼠标到key查看类型
29
+ * watch computed字段时需要手写类型,可悬停鼠标到key查看类型
21
30
  */
22
- // SubComponent<RootDoc, CompDoc>()({
23
- // data: {
24
- // aaa_num: 123,
25
- // },
26
- // computed: {
27
- // _aaa_CNum() {
28
- // return this.data.Pnum + this.data.aaa_num;
29
- // },
30
- // aaa_str() {
31
- // return 123;
32
- // },
33
- // },
34
- // watch: {
35
- // _aaa_CNum(newValue: number, oldValue: number) {
36
- // Checking<number, typeof newValue, Test.Pass>;
37
-
38
- // Checking<number, typeof oldValue, Test.Pass>;
39
- // },
40
- // aaa_str(newValue: 123, oldValue: 123) {
41
- // Checking<123, typeof newValue, Test.Pass>;
42
-
43
- // Checking<123, typeof oldValue, Test.Pass>;
44
- // },
45
- // },
46
- // });
31
+ SubComponent<RootDoc, CompDoc>()({
32
+ computed: {
33
+ aaa_str(): string {
34
+ return this.data.aaa_num.toString();
35
+ },
36
+ aaa_num(): number {
37
+ return 123;
38
+ },
39
+ aaa_bool(): boolean {
40
+ return this.data.bool;
41
+ },
42
+ aaa_obj(): Mock_User {
43
+ return {} as Mock_User;
44
+ },
45
+ },
46
+ watch: {
47
+ aaa_num(newValue: number, oldValue: number) {
48
+ Checking<number, typeof newValue, Test.Pass>;
49
+
50
+ Checking<number, typeof oldValue, Test.Pass>;
51
+ },
52
+ aaa_str(newValue: string, oldValue: string) {
53
+ Checking<string, typeof newValue, Test.Pass>;
54
+
55
+ Checking<string, typeof oldValue, Test.Pass>;
56
+ },
57
+ aaa_bool(newValue: boolean, oldValue: boolean) {
58
+ Checking<boolean, typeof newValue, Test.Pass>;
59
+
60
+ Checking<boolean, typeof oldValue, Test.Pass>;
61
+ },
62
+ aaa_obj(newValue: Mock_User, oldValue: Mock_User | null) {
63
+ Checking<Mock_User, typeof newValue, Test.Pass>;
64
+
65
+ Checking<Mock_User | null, typeof oldValue, Test.Pass>;
66
+ },
67
+ "aaa_obj.id"(newValue: string, oldValue: string) {
68
+ Checking<string, typeof newValue, Test.Pass>;
69
+
70
+ Checking<string, typeof oldValue, Test.Pass>;
71
+ },
72
+ "aaa_obj.age"(newValue: number, oldValue: number) {
73
+ Checking<number, typeof newValue, Test.Pass>;
74
+
75
+ Checking<number, typeof oldValue, Test.Pass>;
76
+ },
77
+ },
78
+ });
@@ -5,7 +5,7 @@ import { SubComponent } from "../..";
5
5
  SubComponent<{ events: { a: string } }, Wm.View>()({
6
6
  watch: {
7
7
  // @ts-expect-error 无可监控字段时,约束为EmptyObject,不可写任何字段
8
- xxx() {},
8
+ nothing() {},
9
9
  },
10
10
  });
11
11
 
@@ -14,7 +14,16 @@ SubComponent<{ events: { a: string } }, Wm.View>()({
14
14
  */
15
15
  SubComponent<{ events: { a: string } }, Wm.View>()({
16
16
  data: {
17
- // @ts-expect-error 超出字段报错
18
- view_classdd: "",
17
+ view_style: "",
18
+ },
19
+ watch: {
20
+ view_style(newValue, oldValue) { // ok
21
+ newValue;
22
+
23
+ oldValue;
24
+ },
25
+ // @ts-expect-error 超出约束字段错误
26
+ view_XXstyle() {
27
+ },
19
28
  },
20
29
  });