annil 1.0.4 → 1.0.5

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 (87) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +79 -10
  3. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js +6 -6
  4. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
  5. package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
  6. package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +3 -3
  7. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +5 -5
  8. package/dist/api/RootComponent/CustomEvents/test/error.test.js +8 -8
  9. package/dist/api/RootComponent/CustomEvents/test/error.test.js.map +1 -1
  10. package/dist/api/RootComponent/CustomEvents/test/normal.test.d.ts +17 -17
  11. package/dist/api/RootComponent/CustomEvents/test/normal.test.js +6 -6
  12. package/dist/api/RootComponent/CustomEvents/test/normal.test.js.map +1 -1
  13. package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js +5 -5
  14. package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js.map +1 -1
  15. package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js +5 -5
  16. package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js.map +1 -1
  17. package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
  18. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
  19. package/dist/api/RootComponent/Properties/GetOptionalDoc.d.ts +2 -2
  20. package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
  21. package/dist/api/RootComponent/Properties/PropertiesConstraint.d.ts +6 -6
  22. package/dist/api/RootComponent/Properties/PropertiesValueValidator.d.ts +2 -2
  23. package/dist/api/RootComponent/Properties/test/error.test.js.map +1 -1
  24. package/dist/api/RootComponent/Properties/test/normalRequired.test.d.ts +21 -21
  25. package/dist/api/SubComponent/SubComputed/GetSubComputedDoc.d.ts +1 -1
  26. package/dist/api/SubComponent/SubComputed/test/normal.test.js +4 -4
  27. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  28. package/dist/api/SubComponent/index.d.ts +1 -1
  29. package/dist/api/SubComponent/index.js.map +1 -1
  30. package/dist/api/navigateTo.d.ts +1 -1
  31. package/dist/index.d.ts +3 -2
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/types/{SpecificType.d.ts → DetailedType.d.ts} +1 -1
  35. package/dist/types/DetailedType.js +2 -0
  36. package/dist/types/DetailedType.js.map +1 -0
  37. package/dist/types/GenerateDoc.d.ts +9 -0
  38. package/dist/types/GenerateDoc.js +2 -0
  39. package/dist/types/GenerateDoc.js.map +1 -0
  40. package/dist/types/InferDetailedType.d.ts +2 -0
  41. package/dist/types/InferDetailedType.js +2 -0
  42. package/dist/types/InferDetailedType.js.map +1 -0
  43. package/dist/types/{InferSpecificType.test.js → InferDetailedType.test.js} +1 -1
  44. package/dist/types/InferDetailedType.test.js.map +1 -0
  45. package/dist/types/OfficialTypeAlias.d.ts +4 -4
  46. package/package.json +1 -1
  47. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +12 -12
  48. package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +4 -4
  49. package/src/api/RootComponent/Computed/test/normal.test.ts +2 -2
  50. package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +3 -3
  51. package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +2 -2
  52. package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +7 -7
  53. package/src/api/RootComponent/CustomEvents/test/error.test.ts +8 -8
  54. package/src/api/RootComponent/CustomEvents/test/normal.test.ts +9 -9
  55. package/src/api/RootComponent/Events/EventsConstraint.ts +1 -1
  56. package/src/api/RootComponent/Instance/test/CustomEventsDoc.test.ts +8 -8
  57. package/src/api/RootComponent/Instance/test/customEvents/normal.test.ts +8 -8
  58. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +3 -3
  59. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +3 -3
  60. package/src/api/RootComponent/Properties/GetOptionalDoc.ts +5 -5
  61. package/src/api/RootComponent/Properties/GetRequiredDoc.ts +5 -5
  62. package/src/api/RootComponent/Properties/PropertiesConstraint.ts +6 -6
  63. package/src/api/RootComponent/Properties/PropertiesOption.ts +1 -1
  64. package/src/api/RootComponent/Properties/PropertiesValueValidator.ts +2 -2
  65. package/src/api/RootComponent/Properties/test/error.test.ts +2 -2
  66. package/src/api/RootComponent/Properties/test/normalOptional.test.ts +8 -8
  67. package/src/api/RootComponent/Properties/test/normalRequired.test.ts +11 -11
  68. package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +2 -2
  69. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +4 -4
  70. package/src/api/SubComponent/SubComputed/test/normal.test.ts +15 -9
  71. package/src/api/SubComponent/index.ts +2 -1
  72. package/src/index.ts +11 -2
  73. package/src/types/DetailedType.ts +15 -0
  74. package/src/types/GenerateDoc.ts +19 -0
  75. package/src/types/InferDetailedType.test.ts +18 -0
  76. package/src/types/{InferSpecificType.ts → InferDetailedType.ts} +4 -4
  77. package/src/types/RestorePropertiesDoc.ts +3 -3
  78. package/tsconfig.json +2 -2
  79. package/dist/types/InferSpecificType.d.ts +0 -2
  80. package/dist/types/InferSpecificType.js +0 -2
  81. package/dist/types/InferSpecificType.js.map +0 -1
  82. package/dist/types/InferSpecificType.test.js.map +0 -1
  83. package/dist/types/SpecificType.js +0 -2
  84. package/dist/types/SpecificType.js.map +0 -1
  85. package/src/types/InferSpecificType.test.ts +0 -18
  86. package/src/types/SpecificType.ts +0 -15
  87. /package/dist/types/{InferSpecificType.test.d.ts → InferDetailedType.test.d.ts} +0 -0
@@ -1,41 +1,41 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { SpecificType } from "../../../../..";
2
+ import type { DetailedType } from "../../../../..";
3
3
  import { RootComponent } from "../../..";
4
4
 
5
5
  RootComponent()({
6
6
  customEvents: {
7
7
  str: String,
8
- num: Number as SpecificType<1 | 2>,
9
- union: [String as SpecificType<"male" | "femal">, Number],
8
+ num: Number as DetailedType<1 | 2>,
9
+ union: [String as DetailedType<"male" | "femal">, Number],
10
10
  null: null,
11
11
  bubbles: {
12
- detailType: String,
12
+ detail: String,
13
13
  options: {
14
14
  bubbles: true,
15
15
  },
16
16
  },
17
17
  capturePhase: {
18
- detailType: Number,
18
+ detail: Number,
19
19
  options: {
20
20
  capturePhase: true,
21
21
  },
22
22
  },
23
23
  bubblesComposed: {
24
- detailType: Number,
24
+ detail: Number,
25
25
  options: {
26
26
  bubbles: true,
27
27
  composed: true,
28
28
  },
29
29
  },
30
30
  capturePhaseComposed: {
31
- detailType: Number,
31
+ detail: Number,
32
32
  options: {
33
33
  capturePhase: true,
34
34
  composed: true,
35
35
  },
36
36
  },
37
37
  bubblesCapturePhaseComposed: {
38
- detailType: null,
38
+ detail: null,
39
39
  options: {
40
40
  bubbles: true,
41
41
  capturePhase: true,
@@ -1,13 +1,13 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
3
- import { RootComponent, type SpecificType } from "../../../../..";
3
+ import { type DetailedType, RootComponent } from "../../../../..";
4
4
 
5
5
  // 组件时
6
6
  RootComponent()({
7
7
  properties: {
8
8
  obj: Object,
9
9
  optionalObj: {
10
- type: Object as SpecificType<{ name: string }>,
10
+ type: Object as DetailedType<{ name: string }>,
11
11
  value: { name: "zhao" },
12
12
  },
13
13
  },
@@ -25,7 +25,7 @@ RootComponent()({
25
25
  properties: {
26
26
  obj: Object,
27
27
  optionalObj: {
28
- type: Object as SpecificType<{ name: string }>,
28
+ type: Object as DetailedType<{ name: string }>,
29
29
  value: { name: "zhao" },
30
30
  },
31
31
  },
@@ -1,5 +1,5 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import { RootComponent, type SpecificType } from "../../../..";
2
+ import { type DetailedType, RootComponent } from "../../../..";
3
3
 
4
4
  import type { RemoveNullOfRequired } from "../../../../types/RemoveNullOfRequired";
5
5
  import type { Mock_User } from "../../Properties/test/normalRequired.test";
@@ -29,11 +29,11 @@ RootComponent()({
29
29
  str: String,
30
30
  obj: Object,
31
31
  union: {
32
- type: Object as SpecificType<Mock_User>,
32
+ type: Object as DetailedType<Mock_User>,
33
33
  value: { id: "001", name: "zhao" },
34
34
  },
35
35
  optionalObject: {
36
- type: Object as SpecificType<Mock_User | null>,
36
+ type: Object as DetailedType<Mock_User | null>,
37
37
  value: null,
38
38
  },
39
39
  },
@@ -1,7 +1,7 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { Select } from "hry-types/src/Object/Select";
3
3
  import type { AddNullForObject } from "../../../types/AddNullForObject";
4
- import type { InferSpecificType } from "../../../types/InferSpecificType";
4
+ import type { InferDetailedType } from "../../../types/InferDetailedType";
5
5
  import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
6
6
 
7
7
  /**
@@ -20,19 +20,19 @@ export type GetOptionalDoc<
20
20
  false,
21
21
  TIsPage,
22
22
  // 组件时 对象加null
23
- AddNullForObject<InferSpecificType<Optional[k]["type"]>>,
23
+ AddNullForObject<InferDetailedType<Optional[k]["type"]>>,
24
24
  // 页面时 对象不加
25
- InferSpecificType<Optional[k]["type"]>
25
+ InferDetailedType<Optional[k]["type"]>
26
26
  >,
27
27
  IfExtends<
28
28
  false,
29
29
  TIsPage,
30
30
  // 组件时 对象加null
31
31
  AddNullForObject<
32
- InferSpecificType<Optional[k]["type"]> | InferSpecificType<(Optional[k]["optionalTypes"] & {})[number]>
32
+ InferDetailedType<Optional[k]["type"]> | InferDetailedType<(Optional[k]["optionalTypes"] & {})[number]>
33
33
  >,
34
34
  // 页面时 对象不加
35
- InferSpecificType<Optional[k]["type"]> | InferSpecificType<(Optional[k]["optionalTypes"] & {})[number]>
35
+ InferDetailedType<Optional[k]["type"]> | InferDetailedType<(Optional[k]["optionalTypes"] & {})[number]>
36
36
  >
37
37
  >;
38
38
  };
@@ -1,7 +1,7 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { Select } from "hry-types/src/Object/Select";
3
3
  import type { AddNullForObject } from "../../../types/AddNullForObject";
4
- import type { InferSpecificType } from "../../../types/InferSpecificType";
4
+ import type { InferDetailedType } from "../../../types/InferDetailedType";
5
5
  import type { PropertiesConstraint, RequiredSingle, RequiredType } from "./PropertiesConstraint";
6
6
 
7
7
  /**
@@ -17,16 +17,16 @@ export type GetRequiredDoc<
17
17
  [k in keyof Required]: IfExtends<
18
18
  Required[k],
19
19
  RequiredSingle,
20
- IfExtends<false, TIsPage, AddNullForObject<InferSpecificType<Required[k]>>, InferSpecificType<Required[k]>>,
20
+ IfExtends<false, TIsPage, AddNullForObject<InferDetailedType<Required[k]>>, InferDetailedType<Required[k]>>,
21
21
  IfExtends<
22
22
  false,
23
23
  TIsPage,
24
24
  // @ts-ignore Required[k] 必为 RequiredUnion
25
- | AddNullForObject<InferSpecificType<Required[k]["type"]>>
25
+ | AddNullForObject<InferDetailedType<Required[k]["type"]>>
26
26
  // @ts-ignore Required[k] 必为 RequiredUnion
27
- | AddNullForObject<InferSpecificType<Required[k]["optionalTypes"][number]>>,
27
+ | AddNullForObject<InferDetailedType<Required[k]["optionalTypes"][number]>>,
28
28
  // @ts-ignore Required[k] 必为 RequiredUnion
29
- InferSpecificType<Required[k]["type"]> | InferSpecificType<Required[k]["optionalTypes"][number]>
29
+ InferDetailedType<Required[k]["type"]> | InferDetailedType<Required[k]["optionalTypes"][number]>
30
30
  >
31
31
  >;
32
32
  };
@@ -1,16 +1,16 @@
1
- import type { SpecificType } from "../../../types/SpecificType";
1
+ import type { DetailedType } from "../../../types/DetailedType";
2
2
 
3
3
  /**
4
4
  * properties 必传(单一)类型
5
5
  */
6
- export type RequiredSingle = SpecificType;
6
+ export type RequiredSingle = DetailedType;
7
7
 
8
8
  /**
9
9
  * properties 必传(联合)类型
10
10
  */
11
11
  export type RequiredUnion<Literal = unknown> = {
12
- type: SpecificType<Literal>;
13
- optionalTypes: SpecificType[];
12
+ type: DetailedType<Literal>;
13
+ optionalTypes: DetailedType[];
14
14
  };
15
15
 
16
16
  /**
@@ -22,9 +22,9 @@ export type RequiredType<Literal = unknown> = RequiredUnion<Literal> | RequiredS
22
22
  * properties 选传类型
23
23
  */
24
24
  export type OptionalType<Literal = unknown> = {
25
- type: SpecificType<Literal>;
25
+ type: DetailedType<Literal>;
26
26
  value: Literal;
27
- optionalTypes?: SpecificType[];
27
+ optionalTypes?: DetailedType[];
28
28
  };
29
29
 
30
30
  /**
@@ -13,7 +13,7 @@ export type PropertiesOption<
13
13
  = // DuplicateFieldCheck extends PropertyKey = "",
14
14
  {
15
15
  /**
16
- * 可通过 as SpecificType<anyType> 书写任意类型
16
+ * 可通过 as DetailedType<anyType> 书写任意类型
17
17
  * @remarks 禁用observable字段,简写或对象写法无value字段时为必传属性(必传对象类型加入null类型),对象写法有value字段为可选属性.
18
18
  */
19
19
  properties?:
@@ -1,5 +1,5 @@
1
1
  import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
2
- import type { InferSpecificType } from "../../../types/InferSpecificType";
2
+ import type { InferDetailedType } from "../../../types/InferDetailedType";
3
3
 
4
4
  /**
5
5
  * 验证properties的value类型是否正确
@@ -12,7 +12,7 @@ export type PropertiesValueValidator<
12
12
  k in keyof TProperties as TProperties[k] extends {
13
13
  type: infer R;
14
14
  value: infer V;
15
- } ? V extends InferSpecificType<R> ? never
15
+ } ? V extends InferDetailedType<R> ? never
16
16
  : k
17
17
  : never
18
18
  ]: { value: () => "⚠️类型错误⚠️" };
@@ -1,4 +1,4 @@
1
- import { RootComponent, type SpecificType } from "../../../../index";
1
+ import { type DetailedType, RootComponent } from "../../../../index";
2
2
  import type { Mock_Cart } from "./normalRequired.test";
3
3
 
4
4
  // 1 非法字段
@@ -35,7 +35,7 @@ RootComponent()({
35
35
  },
36
36
  optionalObj: {
37
37
  // @ts-expect-error 对象默认值要写null则必须先定义
38
- type: Object as SpecificType<Mock_Cart>,
38
+ type: Object as DetailedType<Mock_Cart>,
39
39
  // @ts-expect-error 对象默认值要写null则必须先定义
40
40
  value: null,
41
41
  },
@@ -1,6 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
- import type { SpecificType } from "../../../../types/SpecificType";
3
+ import type { DetailedType } from "../../../../types/DetailedType";
4
4
  import { RootComponent } from "../..";
5
5
  import { type Mock_User } from "./normalRequired.test";
6
6
 
@@ -14,22 +14,22 @@ const OptionalDoc = RootComponent()({
14
14
  value: 123,
15
15
  },
16
16
  optional_gender: {
17
- type: String as SpecificType<"male" | "female">, // 同类字面量联合类型
17
+ type: String as DetailedType<"male" | "female">, // 同类字面量联合类型
18
18
  value: "male",
19
19
  },
20
20
  optional_tuple: {
21
- type: Array as unknown as SpecificType<[number, string, boolean]>, // 元组类型
21
+ type: Array as unknown as DetailedType<[number, string, boolean]>, // 元组类型
22
22
  value: [1, "a", true] as [number, string, boolean],
23
23
  },
24
24
  optional_obj: {
25
- type: Object as SpecificType<Mock_User>, // 对象类型
25
+ type: Object as DetailedType<Mock_User>, // 对象类型
26
26
  value: {
27
27
  id: "id",
28
28
  age: 20,
29
29
  },
30
30
  },
31
31
  optional_objOrNull: {
32
- type: Object as SpecificType<Mock_User | null>, // 对象类型与null的联合
32
+ type: Object as DetailedType<Mock_User | null>, // 对象类型与null的联合
33
33
  value: null,
34
34
  },
35
35
  optional_union: { // 非同类联合类型 string | number
@@ -74,16 +74,16 @@ type OptionalDocExpected = {
74
74
 
75
75
  Checking<typeof OptionalDoc, OptionalDocExpected, Test.Pass>;
76
76
 
77
- // properties 使用SpecificType时,接受interface类型
77
+ // properties 使用DetailedType时,接受interface类型
78
78
  interface Foo {
79
79
  name: string;
80
80
  }
81
81
 
82
82
  RootComponent()({
83
83
  properties: {
84
- xxx: Object as SpecificType<{ dd: Foo }>,
84
+ xxx: Object as DetailedType<{ dd: Foo }>,
85
85
  user: {
86
- type: Object as SpecificType<Foo>,
86
+ type: Object as DetailedType<Foo>,
87
87
  value: { name: "zhao" },
88
88
  },
89
89
  },
@@ -1,5 +1,5 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { SpecificType } from "../../../../types/SpecificType";
2
+ import type { DetailedType } from "../../../../types/DetailedType";
3
3
 
4
4
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
5
5
  import { RootComponent } from "../..";
@@ -30,12 +30,12 @@ export const mock_requiredSingle = {
30
30
  bool: Boolean,
31
31
  arr: Array,
32
32
  obj: Object,
33
- tuple: Array as unknown as SpecificType<[string, number, boolean]>,
34
- union_str: String as SpecificType<"male" | "female">,
35
- union_num: Number as SpecificType<0 | 1 | 2>,
36
- union_bool: Boolean as SpecificType<false | true>,
37
- union_arr: Array as SpecificType<number[] | string[]>,
38
- union_obj: Object as SpecificType<Mock_User | Mock_Cart>,
33
+ tuple: Array as unknown as DetailedType<[string, number, boolean]>,
34
+ union_str: String as DetailedType<"male" | "female">,
35
+ union_num: Number as DetailedType<0 | 1 | 2>,
36
+ union_bool: Boolean as DetailedType<false | true>,
37
+ union_arr: Array as DetailedType<number[] | string[]>,
38
+ union_obj: Object as DetailedType<Mock_User | Mock_Cart>,
39
39
  } satisfies Record<string, RequiredSingle>;
40
40
 
41
41
  /**
@@ -47,16 +47,16 @@ export const mock_requiredUnion = {
47
47
  optionalTypes: [Number, Boolean],
48
48
  },
49
49
  union_literalStr_Literalnum: {
50
- type: String as SpecificType<"male" | "female">,
51
- optionalTypes: [Number as SpecificType<0 | 1 | 2>],
50
+ type: String as DetailedType<"male" | "female">,
51
+ optionalTypes: [Number as DetailedType<0 | 1 | 2>],
52
52
  },
53
53
  union_mockUser_num: {
54
- type: Object as SpecificType<Mock_User>,
54
+ type: Object as DetailedType<Mock_User>,
55
55
  optionalTypes: [Number],
56
56
  },
57
57
  union_num_mockUser: {
58
58
  type: Number,
59
- optionalTypes: [Object as SpecificType<Mock_User>],
59
+ optionalTypes: [Object as DetailedType<Mock_User>],
60
60
  },
61
61
  } satisfies Record<string, RequiredUnion>;
62
62
 
@@ -1,6 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
- import type { SpecificType } from "../../../../types/SpecificType";
3
+ import type { DetailedType } from "../../../../types/DetailedType";
4
4
  import { RootComponent } from "../..";
5
5
  import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
@@ -10,7 +10,7 @@ import type { Mock_User } from "../../Properties/test/normalRequired.test";
10
10
  RootComponent()({
11
11
  properties: {
12
12
  Pnum: Number,
13
- obj: Object as SpecificType<Mock_User>,
13
+ obj: Object as DetailedType<Mock_User>,
14
14
  },
15
15
  data: {
16
16
  DNum: 123,
@@ -3,7 +3,7 @@ import { Checking, type Test } from "hry-types";
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { RootComponent } from "../..";
5
5
 
6
- import type { SpecificType } from "../../../..";
6
+ import type { DetailedType } from "../../../..";
7
7
  // import {
8
8
  // type Mock_Cart,
9
9
  // mock_requiredTypes,
@@ -23,11 +23,11 @@ const mock_optional = {
23
23
  value: 123,
24
24
  },
25
25
  optional_gender: {
26
- type: String as SpecificType<"male" | "female">,
26
+ type: String as DetailedType<"male" | "female">,
27
27
  value: "male" as const,
28
28
  },
29
29
  optional_obj: {
30
- type: Object as SpecificType<Mock_User>,
30
+ type: Object as DetailedType<Mock_User>,
31
31
  value: {
32
32
  id: "id",
33
33
  name: "name",
@@ -35,7 +35,7 @@ const mock_optional = {
35
35
  },
36
36
  },
37
37
  optional_objOrNull: {
38
- type: Object as SpecificType<Mock_User | null>, // 可选类型定义null默认值方可为null
38
+ type: Object as DetailedType<Mock_User | null>, // 可选类型定义null默认值方可为null
39
39
  value: null,
40
40
  },
41
41
  } satisfies Record<string, OptionalType>;
@@ -19,11 +19,18 @@ type Root = {
19
19
  data: {
20
20
  str: string;
21
21
  };
22
+ store: {
23
+ SNum: number;
24
+ };
22
25
  computed: {
23
26
  bool: boolean;
24
27
  };
25
28
  };
26
29
 
30
+ type $aaa = ComponentDoc<
31
+ { properties: { aaa_str: string; aaa_user: User | null; aaa_num: number; aaa_age: number } }
32
+ >;
33
+
27
34
  SubComponent<{}, OnlyCustomCompDoc>()({
28
35
  // 1 CompDoc的properties为空时,可以写{}
29
36
  computed: {},
@@ -76,6 +83,7 @@ SubComponent<Root, OnlyPropsCompDoc>()({
76
83
  ReadonlyDeep<{
77
84
  num: number;
78
85
  user: User | null;
86
+ SNum: number;
79
87
  str: string;
80
88
  bool: boolean;
81
89
  aaa_num: number;
@@ -98,6 +106,7 @@ SubComponent<Root, OnlyPropsCompDoc>()({
98
106
  num: number;
99
107
  user: User | null;
100
108
  str: string;
109
+ SNum: number;
101
110
  bool: boolean;
102
111
  aaa_num: number;
103
112
  aaa_num123: 123;
@@ -110,18 +119,12 @@ SubComponent<Root, OnlyPropsCompDoc>()({
110
119
  },
111
120
  });
112
121
 
113
- // 计算属性可互相引用 !!!但是没有自动提示!!!
114
- type CompDoc = ComponentDoc<
115
- { properties: { aaa_num: number; aaa_user: User | null; aaa_xxx: number; aaa_age: number } }
116
- >;
122
+ // 计算属性可互相引用,但要加返回类型注释
117
123
 
118
- SubComponent<Root, CompDoc>()({
119
- data: {
120
- aaa_xxx: 123,
121
- },
124
+ SubComponent<Root, $aaa>()({
122
125
  computed: {
123
126
  aaa_num(): number {
124
- return this.data.aaa_xxx;
127
+ return this.data.SNum;
125
128
  },
126
129
  aaa_user(): User | null {
127
130
  return this.data.user;
@@ -129,5 +132,8 @@ SubComponent<Root, CompDoc>()({
129
132
  aaa_age(): number {
130
133
  return this.data.aaa_num;
131
134
  },
135
+ aaa_str(): string {
136
+ return this.data.str;
137
+ },
132
138
  },
133
139
  });
@@ -106,7 +106,8 @@ type SubComponentConstructor<
106
106
  AllRootDataDoc extends object =
107
107
  & Required<TRootDoc["properties"]>
108
108
  & TRootDoc["data"]
109
- & TRootDoc["computed"],
109
+ & TRootDoc["computed"]
110
+ & TRootDoc["store"],
110
111
  > = {
111
112
  <
112
113
  TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>,
package/src/index.ts CHANGED
@@ -10,8 +10,17 @@ import { RootComponent } from "./api/RootComponent";
10
10
 
11
11
  import { SubComponent } from "./api/SubComponent";
12
12
 
13
- import type { SpecificType } from "./types/SpecificType";
13
+ import type { DetailedType } from "./types/DetailedType";
14
14
 
15
+ import type { GenerateDoc } from "./types/GenerateDoc";
15
16
  import type { ParamsEqual } from "./types/TwoParamsEqual";
16
17
 
17
- export { DefineComponent, navigateTo, type ParamsEqual, RootComponent, type SpecificType, SubComponent };
18
+ export {
19
+ DefineComponent,
20
+ type DetailedType,
21
+ type GenerateDoc,
22
+ navigateTo,
23
+ type ParamsEqual,
24
+ RootComponent,
25
+ SubComponent,
26
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 通过as DetailedType 指定具体类型。
3
+ * @remarks
4
+ * 在js中使用构造函数(Object,Array等)表示类型时,无法给出明确的类型,DetailedType为此而生
5
+ * @example
6
+ * ``` ts
7
+ * RootComponent()({
8
+ * properties: {
9
+ * gender: String as DetailedType<"male" | "female">,
10
+ * unionArr: Array as DetailedType<string[] | number[]>,
11
+ * },
12
+ * });
13
+ * ```
14
+ */
15
+ export type DetailedType<T = unknown> = { (): T } | { new(...arg: any[]): T };
@@ -0,0 +1,19 @@
1
+ import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
+ import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
3
+ import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
+ import type { AddPrefix } from "./AddPrefix";
5
+
6
+ /**
7
+ * 生成组件文档类型
8
+ */
9
+ export type GenerateDoc<TName extends string, T extends ComponentDoc> = ComputeIntersection<
10
+ & IfExtends<
11
+ unknown,
12
+ T["properties"],
13
+ {},
14
+ {
15
+ properties: AddPrefix<T["properties"] & {}, TName>;
16
+ }
17
+ >
18
+ & IfExtends<unknown, T["customEvents"], {}, { customEvents: AddPrefix<T["customEvents"] & {}, TName> }>
19
+ >;
@@ -0,0 +1,18 @@
1
+ import { Checking, type Test } from "hry-types";
2
+
3
+ import type { DetailedType } from "./DetailedType";
4
+ import type { InferDetailedType } from "./InferDetailedType";
5
+
6
+ Checking<InferDetailedType<StringConstructor>, string, Test.Pass>;
7
+
8
+ Checking<InferDetailedType<NumberConstructor>, number, Test.Pass>;
9
+
10
+ Checking<InferDetailedType<BooleanConstructor>, boolean, Test.Pass>;
11
+
12
+ Checking<InferDetailedType<ArrayConstructor>, unknown[], Test.Pass>;
13
+
14
+ Checking<InferDetailedType<ObjectConstructor>, object, Test.Pass>;
15
+
16
+ Checking<InferDetailedType<DetailedType<"a" | "b">>, "a" | "b", Test.Pass>;
17
+
18
+ Checking<InferDetailedType<DetailedType<[string, number, boolean]>>, [string, number, boolean], Test.Pass>;
@@ -1,12 +1,12 @@
1
- import type { SpecificType } from "./SpecificType";
1
+ import type { DetailedType } from "./DetailedType";
2
2
 
3
3
  /**
4
- * 解析SpecificType的真实类型
4
+ * 解析DetailedType的类型
5
5
  */
6
- export type InferSpecificType<T> = T extends StringConstructor ? string
6
+ export type InferDetailedType<T> = T extends StringConstructor ? string
7
7
  : T extends NumberConstructor ? number
8
8
  : T extends BooleanConstructor ? boolean
9
9
  : T extends ArrayConstructor ? unknown[]
10
10
  : T extends ObjectConstructor ? object
11
- : T extends SpecificType<infer R> ? R
11
+ : T extends DetailedType<infer R> ? R
12
12
  : never;
@@ -3,7 +3,7 @@
3
3
 
4
4
  // import type { ListOfSamePrimitive } from "./ListOfSamePrimitive";
5
5
  // import type { ReStorePropTypeOfList } from "./ReStorePropTypeOfList";
6
- // import type { SpecificType } from "./SpecificType";
6
+ // import type { DetailedType } from "./DetailedType";
7
7
 
8
8
  /**
9
9
  * 还原properties描述
@@ -16,9 +16,9 @@
16
16
  */
17
17
  // type ReStorePropertiesDoc<T extends ComponentDoc> = {
18
18
  // [k in keyof T]?: ListOfSamePrimitive<T[k]> extends infer R extends unknown[]
19
- // ? R["length"] extends 1 ? SpecificType<R[0]> | { type: SpecificType<R[0]>; value: R[0] }
19
+ // ? R["length"] extends 1 ? DetailedType<R[0]> | { type: DetailedType<R[0]>; value: R[0] }
20
20
  // : {
21
- // type: SpecificType<R[0]>;
21
+ // type: DetailedType<R[0]>;
22
22
  // value?: R[0];
23
23
  // optionalTypes?: ReStorePropTypeOfList<Drop<R, R[0]>>[number][];
24
24
  // }
package/tsconfig.json CHANGED
@@ -22,8 +22,8 @@
22
22
  "ignoreDeprecations": "5.0",
23
23
  "noFallthroughCasesInSwitch": true, // 报告switch语句中漏接情况的错误
24
24
  "allowSyntheticDefaultImports": true, // esModuleInterop 为true时自动true
25
- // 指定加载包的路径,默认加载所有@types下的包 包含上级目录
26
- "types": ["./node_modules/hry-types", "./node_modules/mobx", "jest", "./node_modules/miniprogram-api-typings/"]
25
+ // 默认加载所有@types下的包 types指定具体的包,其他拒绝。包含上级目录
26
+ "types": ["hry-types", "mobx", "jest", "miniprogram-api-typings"]
27
27
  },
28
28
  "include": ["**/*.ts"]
29
29
  }
@@ -1,2 +0,0 @@
1
- import type { SpecificType } from "./SpecificType";
2
- export type InferSpecificType<T> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? unknown[] : T extends ObjectConstructor ? object : T extends SpecificType<infer R> ? R : never;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=InferSpecificType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InferSpecificType.js","sourceRoot":"","sources":["../../src/types/InferSpecificType.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"InferSpecificType.test.js","sourceRoot":"","sources":["../../src/types/InferSpecificType.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,WAAW,CAAC;AAKhD,QAAiE,CAAC;AAElE,QAAiE,CAAC;AAElE,QAAmE,CAAC;AAEpE,QAAmE,CAAC;AAEpE,QAAiE,CAAC;AAElE,QAA0E,CAAC;AAE3E,QAA0G,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SpecificType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpecificType.js","sourceRoot":"","sources":["../../src/types/SpecificType.ts"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import { Checking, type Test } from "hry-types";
2
-
3
- import type { InferSpecificType } from "./InferSpecificType";
4
- import type { SpecificType } from "./SpecificType";
5
-
6
- Checking<InferSpecificType<StringConstructor>, string, Test.Pass>;
7
-
8
- Checking<InferSpecificType<NumberConstructor>, number, Test.Pass>;
9
-
10
- Checking<InferSpecificType<BooleanConstructor>, boolean, Test.Pass>;
11
-
12
- Checking<InferSpecificType<ArrayConstructor>, unknown[], Test.Pass>;
13
-
14
- Checking<InferSpecificType<ObjectConstructor>, object, Test.Pass>;
15
-
16
- Checking<InferSpecificType<SpecificType<"a" | "b">>, "a" | "b", Test.Pass>;
17
-
18
- Checking<InferSpecificType<SpecificType<[string, number, boolean]>>, [string, number, boolean], Test.Pass>;