annil 1.5.13 → 1.5.15

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 CHANGED
@@ -4,6 +4,20 @@
4
4
 
5
5
  * 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
6
6
 
7
+ ## [1.5.15](https://github.com/missannil/annil/compare/v1.5.14...v1.5.15) (2024-01-15)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * subComputed约束 去除默认{} ([054cb48](https://github.com/missannil/annil/commit/054cb482cdc6c84e820d69d163b9cafe0c01de81))
13
+
14
+ ## [1.5.14](https://github.com/missannil/annil/compare/v1.5.13...v1.5.14) (2024-01-15)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * subComponents的data字段和store字段加入isReady字段和内部字段 ([06a22e0](https://github.com/missannil/annil/commit/06a22e0faff21dbc1e96862f190b2af11db55603))
20
+
7
21
  ## [1.5.13](https://github.com/missannil/annil/compare/v1.5.12...v1.5.13) (2024-01-12)
8
22
 
9
23
 
@@ -1,4 +1,4 @@
1
1
  import type { V } from "hry-types";
2
- export type SubComputedOption<TComputed extends object, legal extends Record<PropertyKey, unknown>> = {
3
- computed?: TComputed & V.IllegalFieldValidator<TComputed, keyof legal, 0, "", "重复或无效的字段">;
2
+ export type SubComputedOption<TComputed extends object, legal extends PropertyKey> = {
3
+ computed?: TComputed & V.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
4
4
  };
@@ -1,4 +1,5 @@
1
1
  import type { V } from "hry-types";
2
+ import type { InnerFields } from "../../../types/InnerData";
2
3
  export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
3
- data?: TSubData & V.IllegalFieldValidator<TSubData, legalKeys | `_${TPrefix}_${string}`, 0, "", "⚠️ 子组件无需此字段或与Inherit字段重复 ⚠️">;
4
+ data?: TSubData & V.IllegalFieldValidator<TSubData, legalKeys | InnerFields<TPrefix>, 0, "", "子组件无需此字段或与Inherit字段重复">;
4
5
  };
@@ -1,3 +1,4 @@
1
- export type SubInheritOption<TInherit> = {
2
- inherit?: TInherit;
1
+ import type { V } from "hry-types";
2
+ export type SubInheritOption<TInherit extends object, legalKeys extends PropertyKey> = {
3
+ inherit?: TInherit & V.IllegalFieldValidator<TInherit, legalKeys, 0, "">;
3
4
  };
@@ -1,4 +1,5 @@
1
1
  import type { V } from "hry-types";
2
- export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey> = {
3
- store?: TSubStore & V.IllegalFieldValidator<TSubStore, legalKeys, 0, "", "与inherit和data字段重复或前缀错误">;
2
+ import type { InnerFields } from "../../../types/InnerData";
3
+ export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
4
+ store?: TSubStore & V.IllegalFieldValidator<TSubStore, legalKeys | InnerFields<TPrefix>, 0, "", "与inherit和data字段重复或前缀错误">;
4
5
  };
@@ -5,6 +5,8 @@ import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
5
5
  import type { ReplacePrefix } from "../../types/ReplacePrefix";
6
6
  import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
7
7
  import type { Func } from "hry-types/src/Misc/Func";
8
+ import type { Extra } from "../../types/Extra";
9
+ import type { InnerFields } from "../../types/InnerData";
8
10
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
9
11
  import type { Replace } from "../../types/Replace";
10
12
  import type { IInjectStore } from "../InstanceInject/instanceConfig";
@@ -35,11 +37,11 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
35
37
  import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
36
38
  import type { SubStoreOption } from "./SubStore/SubStoreOption";
37
39
  import type { SubWatchOption } from "./SubWatch/SubWatchOption";
38
- type Options<RootDoc extends RootComponentDoc, IsPage extends boolean, CurrentCompDoc extends ComponentDoc, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object> = SubInheritOption<TInherit> & SubDataOption<TSubData, Exclude<keyof CurrentCompDoc["properties"], (keyof InheritDoc)>, Prefix> & SubStoreOption<TSubStore, Exclude<keyof CurrentCompDoc["properties"], (keyof (InheritDoc & SubDataDoc))>> & SubComputedOption<TSubComputed, Omit<CurrentCompDoc["properties"], (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, RootDoc["properties"] & {}> & SubLifetimesOption & SubWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & SubObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<SubInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, RootDoc["customEvents"] & {}, SubStoreDoc>>;
40
+ type Options<RootDoc extends RootComponentDoc, IsPage extends boolean, CurrentCompDoc extends ComponentDoc, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object, CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"]> = SubInheritOption<TInherit, CompDocKeys> & SubDataOption<TSubData, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof InheritDoc)>, Prefix> & SubStoreOption<TSubStore, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>, Prefix> & SubComputedOption<TSubComputed, Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & SubLifetimesOption & SubWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & SubObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<SubInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
39
41
  type SubComponentConstructor<TRootDoc extends RootComponentDoc, TOriginalCompDoc extends ComponentDoc, TSupplementalPrefix extends string = "", IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false, CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`, CurrentCompDoc extends ComponentDoc = IfExtends<TSupplementalPrefix, "", TOriginalCompDoc, ReplacePrefix<TOriginalCompDoc, CurrentPrefix>>, AllRootDataDoc extends object = Required<TRootDoc["properties"]> & TRootDoc["data"] & TRootDoc["computed"] & TRootDoc["store"]> = {
40
- <TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>> = {}, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>, TSubStore, {}, {
41
- [k in keyof TSubStore]: ReturnType<TSubStore[k] & {}>;
42
- }>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<CurrentCompDoc["properties"] & {}>, keyof (InheritDoc & SubDataDoc & SubStoreDoc & IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>)>>(options: Options<TRootDoc, IsPage, CurrentCompDoc, CurrentPrefix, AllRootDataDoc, TInherit, TSubData, TSubStore, TSubComputed, TEvents, TSubMethods, InheritDoc, SubDataDoc, SubStoreDoc, SubComputedDoc, SubEventsDoc, SubMethodsDoc>): CreateSubComponentDoc<TOriginalCompDoc["customEvents"] & {}, SubEventsDoc, MissingRequiredField>;
42
+ <TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore, {}, {
43
+ [k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>>;
44
+ }>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>, keyof (InheritDoc & SubDataDoc & SubStoreDoc & IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>)>>(options: Options<TRootDoc, IsPage, CurrentCompDoc, CurrentPrefix, AllRootDataDoc, TInherit, TSubData, TSubStore, TSubComputed, TEvents, TSubMethods, InheritDoc, SubDataDoc, SubStoreDoc, SubComputedDoc, SubEventsDoc, SubMethodsDoc>): CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
43
45
  };
44
46
  export declare function SubComponent<RootDoc extends RootComponentDoc, CompDoc extends ComponentDoc, Prefix extends string = "">(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>>;
45
47
  export type SubComponentTrueOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"AAkNA,MAAM,UAAU,YAAY;IAK1B,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAkC,CAAQ,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"AAyOA,MAAM,UAAU,YAAY;IAK1B,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAkC,CAAQ,CAAC;AACvE,CAAC"}
@@ -0,0 +1 @@
1
+ export type Extra<Prefix extends string> = Record<`${Prefix}_isReady`, boolean>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Extra.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Extra.js","sourceRoot":"","sources":["../../src/types/Extra.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export type InnerFields<Prefix extends string> = `_${Prefix}_${string}`;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=InnerData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InnerData.js","sourceRoot":"","sources":["../../src/types/InnerData.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "annil",
3
- "version": "1.5.13",
3
+ "version": "1.5.15",
4
4
  "description": "微信小程序(原生开发)插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -1,9 +1,9 @@
1
1
  import type { V } from "hry-types";
2
2
  export type SubComputedOption<
3
3
  TComputed extends object,
4
- legal extends Record<PropertyKey, unknown>,
4
+ legal extends PropertyKey,
5
5
  > = {
6
6
  computed?:
7
7
  & TComputed
8
- & V.IllegalFieldValidator<TComputed, keyof legal, 0, "", "重复或无效的字段">;
8
+ & V.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
9
9
  };
@@ -48,3 +48,16 @@ SubComponent<{}, OnlyPropsCompDoc>()({
48
48
  },
49
49
  },
50
50
  });
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,5 +140,18 @@ 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
+ },
143
156
  },
144
157
  });
@@ -1,4 +1,5 @@
1
1
  import type { V } from "hry-types";
2
+ import type { InnerFields } from "../../../types/InnerData";
2
3
 
3
4
  export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
4
5
  /**
@@ -9,9 +10,9 @@ export type SubDataOption<TSubData extends object, legalKeys extends PropertyKey
9
10
  & TSubData
10
11
  & V.IllegalFieldValidator<
11
12
  TSubData,
12
- legalKeys | `_${TPrefix}_${string}`,
13
+ legalKeys | InnerFields<TPrefix>,
13
14
  0,
14
15
  "",
15
- "⚠️ 子组件无需此字段或与Inherit字段重复 ⚠️"
16
+ "子组件无需此字段或与Inherit字段重复"
16
17
  >;
17
18
  };
@@ -27,7 +27,6 @@ SubComponent<{}, CompDoc>()({
27
27
  },
28
28
  });
29
29
 
30
- //
31
30
  SubComponent<{ data: { _num: number } }, CompDoc>()({
32
31
  inherit: {
33
32
  aaa_str: "wxml",
@@ -35,11 +34,22 @@ SubComponent<{ data: { _num: number } }, CompDoc>()({
35
34
  aaa_obj: "wxml",
36
35
  },
37
36
  data: {
38
- // 3 CompDoc去除Inherit字段后为空时,可写内部字段
37
+ // 3 可写内部字段
39
38
  _aaa_str: "str",
40
39
  },
41
40
  });
42
41
 
42
+ //
43
+ SubComponent<{ data: { _num: number } }, CompDoc>()({
44
+ inherit: {
45
+ aaa_str: "wxml",
46
+ },
47
+ data: {
48
+ // 4 可写isReady 特许字段 ExtraFields
49
+ aaa_isReady: false,
50
+ },
51
+ });
52
+
43
53
  SubComponent<{}, CompDoc>()({
44
54
  data: {
45
55
  aaa_str: "a",
@@ -1,8 +1,17 @@
1
- export type SubInheritOption<TInherit> = {
1
+ import type { V } from "hry-types";
2
+
3
+ export type SubInheritOption<TInherit extends object, legalKeys extends PropertyKey> = {
2
4
  /**
3
5
  * 继承来自根组件的数据(key)或'wxml',wxml表示数据来自`.wxml`文件(例如数据来自父元素循环wx:for的数据).
4
6
  * inherit字段最终会在选项中删除,它的存在是为了ts开发时提供心智模型(类型检测),js开发好比注释功能.便于代码阅读。
5
7
  * 带类型检测
6
8
  */
7
- inherit?: TInherit;
9
+ inherit?:
10
+ & TInherit
11
+ & V.IllegalFieldValidator<
12
+ TInherit,
13
+ legalKeys,
14
+ 0,
15
+ ""
16
+ >;
8
17
  };
@@ -62,3 +62,15 @@ DefineComponent({
62
62
  // @ts-expect-error 2 不能将类型“string”分配给类型“_SubComponentDoc”。
63
63
  subComponents: [subDoc],
64
64
  });
65
+
66
+ // 3 错误的key检查
67
+
68
+ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
69
+ inherit: {
70
+ aaa_num: "required_num",
71
+ // @ts-expect-error 3.1 不存在于组件中的key给错误提示
72
+ xxx: "",
73
+ // @ts-expect-error 3.2 不存在于组件中的key给错误提示
74
+ aaa_xxx: "",
75
+ },
76
+ });
@@ -1,6 +1,7 @@
1
1
  import type { V } from "hry-types";
2
+ import type { InnerFields } from "../../../types/InnerData";
2
3
 
3
- export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey> = {
4
+ export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyKey, TPrefix extends string> = {
4
5
  /**
5
6
  * 全局响应式数据字段,全局store对应数据变化实例对应数据自动setData。
6
7
  * 约束为组件properties字段去除inherit和data的剩余字段和内部字段
@@ -19,8 +20,8 @@ export type SubStoreOption<TSubStore extends object, legalKeys extends PropertyK
19
20
  & TSubStore
20
21
  & V.IllegalFieldValidator<
21
22
  TSubStore,
22
- legalKeys,
23
- // legalKeys | `_${TPrefix}_${string}`,
23
+ // legalKeys,
24
+ legalKeys | InnerFields<TPrefix>,
24
25
  0,
25
26
  "",
26
27
  "与inherit和data字段重复或前缀错误"
@@ -25,6 +25,7 @@ SubComponent<{
25
25
  },
26
26
  data: {
27
27
  aaa_num: 20,
28
+ aaa_isReady: false,
28
29
  },
29
30
  store: {
30
31
  // @ts-expect-error 1 与 inherit 字段重复
@@ -33,5 +34,9 @@ SubComponent<{
33
34
  aaa_num: () => user.age,
34
35
  // @ts-expect-error 3 超出约束字段
35
36
  num: () => user.age,
37
+ // @ts-expect-error 4 于data字段重复
38
+ aaa_isReady() {
39
+ return false;
40
+ },
36
41
  },
37
42
  });
@@ -16,20 +16,22 @@ type DocA = ComponentDoc<{
16
16
 
17
17
  SubComponent<{}, DocA>()({
18
18
  store: {
19
+ // 1 可写组件字段
19
20
  aaa_str: () => user.name,
20
-
21
21
  aaa_num: () => user.age,
22
- // 内部字段
23
- // _aaa_ddd: () => user.age,
24
22
  },
25
23
  });
26
24
 
27
25
  SubComponent<{}, DocA, "a">()({
28
26
  store: {
29
- aaaA_str: () => user.name,
27
+ // 2 可写内部字段
28
+ _aaaA_xxxxxx: () => user.age,
29
+ },
30
+ });
30
31
 
31
- aaaA_num: () => user.age,
32
- // 内部字段
33
- // _aaaA_ddd: () => user.age,
32
+ SubComponent<{}, DocA, "a">()({
33
+ store: {
34
+ // 3 可写特许字段
35
+ aaaA_isReady: () => false,
34
36
  },
35
37
  });
@@ -6,6 +6,8 @@ import type { ReplacePrefix } from "../../types/ReplacePrefix";
6
6
  import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
7
7
 
8
8
  import type { Func } from "hry-types/src/Misc/Func";
9
+ import type { Extra } from "../../types/Extra";
10
+ import type { InnerFields } from "../../types/InnerData";
9
11
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
10
12
  import type { Replace } from "../../types/Replace";
11
13
  import type { IInjectStore } from "../InstanceInject/instanceConfig";
@@ -55,27 +57,28 @@ type Options<
55
57
  SubComputedDoc extends object,
56
58
  SubEventsDoc extends object,
57
59
  SubMethodsDoc extends object,
60
+ CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"],
58
61
  > =
59
- & SubInheritOption<TInherit>
62
+ & SubInheritOption<TInherit, CompDocKeys>
60
63
  & SubDataOption<
61
64
  TSubData,
62
- Exclude<keyof CurrentCompDoc["properties"], (keyof InheritDoc)>,
65
+ Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof InheritDoc)>,
63
66
  Prefix
64
67
  >
65
68
  & SubStoreOption<
66
69
  TSubStore,
67
- Exclude<keyof CurrentCompDoc["properties"], (keyof (InheritDoc & SubDataDoc))>
70
+ Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc))>,
71
+ Prefix
68
72
  >
69
73
  & SubComputedOption<
70
74
  TSubComputed,
71
- // AllRootDataDoc & SubDataDoc & SubDataDoc & SubComputedDoc,
72
75
  // 合法的配置
73
- Omit<CurrentCompDoc["properties"], (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>
76
+ Exclude<CompDocKeys | keyof Extra<Prefix>, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>
74
77
  >
75
78
  // 无需与根组件的events字段重复检测,因为根组件多了bubbles字段,一定不会重复
76
79
  & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>>
77
80
  & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)>
78
- & SubPageLifetimesOption<IsPage, RootDoc["properties"] & {}>
81
+ & SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>>
79
82
  & SubLifetimesOption
80
83
  & SubWatchOption<
81
84
  & SubComputedDoc
@@ -97,7 +100,7 @@ type Options<
97
100
  SubMethodsDoc & RootDoc["methods"],
98
101
  Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>,
99
102
  AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>,
100
- RootDoc["customEvents"] & {},
103
+ NonNullable<RootDoc["customEvents"]>,
101
104
  SubStoreDoc
102
105
  >
103
106
  >;
@@ -126,31 +129,51 @@ type SubComponentConstructor<
126
129
  > = {
127
130
  <
128
131
  TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>,
129
- TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>,
130
- TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>,
132
+ TSubData extends SubDataConstraint<
133
+ & Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc>
134
+ & Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
135
+ >,
136
+ TSubStore extends SubStoreConstraint<
137
+ & Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)>
138
+ & Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
139
+ >,
131
140
  TEvents extends SubEventsConstraint<CurrentCompDoc>,
132
141
  // 加默认值计算字段无提示且需要手写返回类型,不加watch无法对computed监控
133
142
  TSubComputed extends SubComputedConstraint<
134
- Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
135
- > = {},
143
+ & Omit<
144
+ Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>,
145
+ keyof (InheritDoc & SubDataDoc & SubStoreDoc)
146
+ >
147
+ & Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
148
+ >,
136
149
  TSubMethods extends SubMethodsConstraint = {},
137
150
  InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>,
138
151
  SubDataDoc extends object = IfExtends<
139
- SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc>>,
152
+ SubDataConstraint<
153
+ & Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof InheritDoc>
154
+ & Record<InnerFields<CurrentPrefix>, unknown>
155
+ >,
140
156
  TSubData,
141
157
  {},
142
158
  TSubData
143
159
  >,
144
160
  SubStoreDoc extends object = IfExtends<
145
- SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)>>,
161
+ SubStoreConstraint<
162
+ & Omit<Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>, keyof (InheritDoc & SubDataDoc)>
163
+ & Record<InnerFields<CurrentPrefix>, unknown>
164
+ >,
146
165
  TSubStore,
147
166
  {},
148
- { [k in keyof TSubStore]: ReturnType<TSubStore[k] & {}> }
167
+ { [k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>> }
149
168
  >,
150
169
  // 无效的计算
151
170
  SubComputedDoc extends object = IfExtends<
152
171
  SubComputedConstraint<
153
- Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
172
+ & Omit<
173
+ Required<CurrentCompDoc["properties"]> & Extra<CurrentPrefix>,
174
+ keyof (InheritDoc & SubDataDoc & SubStoreDoc)
175
+ >
176
+ & Record<InnerFields<CurrentPrefix>, unknown> // 内部字段
154
177
  >,
155
178
  TSubComputed,
156
179
  {},
@@ -165,7 +188,7 @@ type SubComponentConstructor<
165
188
  SubMethodsDoc extends object = TSubMethods,
166
189
  // 缺失的必传字段(配置中inhrit,data,computed的字段不包含的必传字段)
167
190
  MissingRequiredField extends PropertyKey = Exclude<
168
- RequiredKeys<CurrentCompDoc["properties"] & {}>,
191
+ RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>,
169
192
  keyof (
170
193
  & InheritDoc
171
194
  & SubDataDoc
@@ -201,7 +224,7 @@ type SubComponentConstructor<
201
224
  SubEventsDoc,
202
225
  SubMethodsDoc
203
226
  >,
204
- ): CreateSubComponentDoc<TOriginalCompDoc["customEvents"] & {}, SubEventsDoc, MissingRequiredField>;
227
+ ): CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
205
228
  };
206
229
 
207
230
  /**
@@ -0,0 +1 @@
1
+ export type Extra<Prefix extends string> = Record<`${Prefix}_isReady`, boolean>;
@@ -0,0 +1 @@
1
+ export type InnerFields<Prefix extends string> = `_${Prefix}_${string}`;