annil 1.0.4 → 1.0.6
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 +15 -1
- package/README.md +79 -10
- package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js +6 -6
- package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
- package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +3 -3
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +5 -5
- package/dist/api/RootComponent/CustomEvents/test/error.test.js +8 -8
- package/dist/api/RootComponent/CustomEvents/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/test/normal.test.d.ts +17 -17
- package/dist/api/RootComponent/CustomEvents/test/normal.test.js +6 -6
- package/dist/api/RootComponent/CustomEvents/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js +5 -5
- package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js +5 -5
- package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
- package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/GetOptionalDoc.d.ts +2 -2
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +2 -2
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
- package/dist/api/RootComponent/Properties/PropertiesConstraint.d.ts +12 -12
- package/dist/api/RootComponent/Properties/PropertiesValueValidator.d.ts +2 -2
- package/dist/api/RootComponent/Properties/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalOptional.test.js +8 -0
- package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalRequired.test.d.ts +21 -21
- package/dist/api/RootComponent/index.d.ts +1 -1
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubComputed/GetSubComputedDoc.d.ts +1 -1
- package/dist/api/SubComponent/SubComputed/test/normal.test.js +4 -4
- package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/index.d.ts +1 -1
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/api/navigateTo.d.ts +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/{SpecificType.d.ts → DetailedType.d.ts} +1 -1
- package/dist/types/DetailedType.js +2 -0
- package/dist/types/DetailedType.js.map +1 -0
- package/dist/types/GenerateDoc.d.ts +9 -0
- package/dist/types/GenerateDoc.js +2 -0
- package/dist/types/GenerateDoc.js.map +1 -0
- package/dist/types/InferDetailedType.d.ts +2 -0
- package/dist/types/InferDetailedType.js +2 -0
- package/dist/types/InferDetailedType.js.map +1 -0
- package/dist/types/{InferSpecificType.test.js → InferDetailedType.test.js} +1 -1
- package/dist/types/InferDetailedType.test.js.map +1 -0
- package/dist/types/OfficialTypeAlias.d.ts +4 -4
- package/package.json +2 -2
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +12 -12
- package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +4 -4
- package/src/api/RootComponent/Computed/test/normal.test.ts +2 -2
- package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +3 -3
- package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +2 -2
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +7 -7
- package/src/api/RootComponent/CustomEvents/test/error.test.ts +8 -8
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +9 -9
- package/src/api/RootComponent/Events/EventsConstraint.ts +1 -1
- package/src/api/RootComponent/Instance/test/CustomEventsDoc.test.ts +8 -8
- package/src/api/RootComponent/Instance/test/customEvents/normal.test.ts +8 -8
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +3 -3
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +3 -3
- package/src/api/RootComponent/Properties/GetOptionalDoc.ts +5 -5
- package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +3 -3
- package/src/api/RootComponent/Properties/GetRequiredDoc.ts +5 -5
- package/src/api/RootComponent/Properties/PropertiesConstraint.ts +12 -12
- package/src/api/RootComponent/Properties/PropertiesOption.ts +1 -1
- package/src/api/RootComponent/Properties/PropertiesValueValidator.ts +2 -2
- package/src/api/RootComponent/Properties/test/error.test.ts +2 -2
- package/src/api/RootComponent/Properties/test/normalOptional.test.ts +22 -8
- package/src/api/RootComponent/Properties/test/normalRequired.test.ts +11 -11
- package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +2 -2
- package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +4 -4
- package/src/api/RootComponent/index.ts +1 -8
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +15 -9
- package/src/api/SubComponent/index.ts +2 -1
- package/src/index.ts +11 -2
- package/src/types/DetailedType.ts +15 -0
- package/src/types/GenerateDoc.ts +19 -0
- package/src/types/InferDetailedType.test.ts +18 -0
- package/src/types/{InferSpecificType.ts → InferDetailedType.ts} +4 -4
- package/src/types/RestorePropertiesDoc.ts +3 -3
- package/tsconfig.json +2 -2
- package/dist/types/InferSpecificType.d.ts +0 -2
- package/dist/types/InferSpecificType.js +0 -2
- package/dist/types/InferSpecificType.js.map +0 -1
- package/dist/types/InferSpecificType.test.js.map +0 -1
- package/dist/types/SpecificType.js +0 -2
- package/dist/types/SpecificType.js.map +0 -1
- package/src/types/InferSpecificType.test.ts +0 -18
- package/src/types/SpecificType.ts +0 -15
- /package/dist/types/{InferSpecificType.test.d.ts → InferDetailedType.test.d.ts} +0 -0
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DetailedType } from "../../../..";
|
|
3
3
|
import { RootComponent } from "../..";
|
|
4
4
|
RootComponent()({
|
|
5
5
|
customEvents: {
|
|
6
6
|
str: String,
|
|
7
|
-
num: Number as
|
|
8
|
-
union: [String as
|
|
7
|
+
num: Number as DetailedType<1 | 2>,
|
|
8
|
+
union: [String as DetailedType<"male" | "femal">, Number],
|
|
9
9
|
null: null,
|
|
10
10
|
bubbles: {
|
|
11
|
-
|
|
11
|
+
detail: String,
|
|
12
12
|
options: {
|
|
13
13
|
bubbles: true,
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
capturePhase: {
|
|
17
|
-
|
|
17
|
+
detail: Number,
|
|
18
18
|
options: {
|
|
19
19
|
capturePhase: true,
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
bubblesComposed: {
|
|
23
|
-
|
|
23
|
+
detail: Number,
|
|
24
24
|
options: {
|
|
25
25
|
bubbles: true,
|
|
26
26
|
composed: true,
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
capturePhaseComposed: {
|
|
30
|
-
|
|
30
|
+
detail: Number,
|
|
31
31
|
options: {
|
|
32
32
|
capturePhase: true,
|
|
33
33
|
composed: true,
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
bubblesCapturePhaseComposed: {
|
|
37
|
-
|
|
37
|
+
detail: null,
|
|
38
38
|
options: {
|
|
39
39
|
bubbles: true,
|
|
40
40
|
capturePhase: true,
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
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
|
|
9
|
-
union: [String as
|
|
8
|
+
num: Number as DetailedType<1 | 2>,
|
|
9
|
+
union: [String as DetailedType<"male" | "femal">, Number],
|
|
10
10
|
null: null,
|
|
11
11
|
bubbles: {
|
|
12
|
-
|
|
12
|
+
detail: String,
|
|
13
13
|
options: {
|
|
14
14
|
bubbles: true,
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
capturePhase: {
|
|
18
|
-
|
|
18
|
+
detail: Number,
|
|
19
19
|
options: {
|
|
20
20
|
capturePhase: true,
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
bubblesComposed: {
|
|
24
|
-
|
|
24
|
+
detail: Number,
|
|
25
25
|
options: {
|
|
26
26
|
bubbles: true,
|
|
27
27
|
composed: true,
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
capturePhaseComposed: {
|
|
31
|
-
|
|
31
|
+
detail: Number,
|
|
32
32
|
options: {
|
|
33
33
|
capturePhase: true,
|
|
34
34
|
composed: true,
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
bubblesCapturePhaseComposed: {
|
|
38
|
-
|
|
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 {
|
|
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
|
|
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
|
|
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 {
|
|
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
|
|
32
|
+
type: Object as DetailedType<Mock_User>,
|
|
33
33
|
value: { id: "001", name: "zhao" },
|
|
34
34
|
},
|
|
35
35
|
optionalObject: {
|
|
36
|
-
type: Object as
|
|
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 {
|
|
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<
|
|
23
|
+
AddNullForObject<InferDetailedType<Optional[k]["type"]>>,
|
|
24
24
|
// 页面时 对象不加
|
|
25
|
-
|
|
25
|
+
InferDetailedType<Optional[k]["type"]>
|
|
26
26
|
>,
|
|
27
27
|
IfExtends<
|
|
28
28
|
false,
|
|
29
29
|
TIsPage,
|
|
30
30
|
// 组件时 对象加null
|
|
31
31
|
AddNullForObject<
|
|
32
|
-
|
|
32
|
+
InferDetailedType<Optional[k]["type"]> | InferDetailedType<(Optional[k]["optionalTypes"] & {})[number]>
|
|
33
33
|
>,
|
|
34
34
|
// 页面时 对象不加
|
|
35
|
-
|
|
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
|
|
|
4
|
-
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
4
|
+
import type { ComputeIntersection, NonReadonlyDeep } from "hry-types/src/Object/_api";
|
|
5
5
|
import type { GetOptionalDoc } from "./GetOptionalDoc";
|
|
6
6
|
import type { GetRequiredDoc } from "./GetRequiredDoc";
|
|
7
7
|
import type { OptionalType, PropertiesConstraint } from "./PropertiesConstraint";
|
|
@@ -10,8 +10,8 @@ type _GetPropertiesDoc<
|
|
|
10
10
|
TProperties extends PropertiesConstraint,
|
|
11
11
|
TIsPage extends boolean,
|
|
12
12
|
Type extends "Required" | "Optional" | "all" = "all",
|
|
13
|
-
OptionalDoc = GetOptionalDoc<Select<TProperties, OptionalType>, TIsPage
|
|
14
|
-
RequiredDoc = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>, TIsPage
|
|
13
|
+
OptionalDoc = NonReadonlyDeep<GetOptionalDoc<Select<TProperties, OptionalType>, TIsPage>>,
|
|
14
|
+
RequiredDoc = NonReadonlyDeep<GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>, TIsPage>>,
|
|
15
15
|
> = IfExtends<
|
|
16
16
|
Type,
|
|
17
17
|
"all",
|
|
@@ -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 {
|
|
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<
|
|
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<
|
|
25
|
+
| AddNullForObject<InferDetailedType<Required[k]["type"]>>
|
|
26
26
|
// @ts-ignore Required[k] 必为 RequiredUnion
|
|
27
|
-
| AddNullForObject<
|
|
27
|
+
| AddNullForObject<InferDetailedType<Required[k]["optionalTypes"][number]>>,
|
|
28
28
|
// @ts-ignore Required[k] 必为 RequiredUnion
|
|
29
|
-
|
|
29
|
+
InferDetailedType<Required[k]["type"]> | InferDetailedType<Required[k]["optionalTypes"][number]>
|
|
30
30
|
>
|
|
31
31
|
>;
|
|
32
32
|
};
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DetailedType } from "../../../types/DetailedType";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* properties 必传(单一)类型
|
|
5
5
|
*/
|
|
6
|
-
export type RequiredSingle =
|
|
6
|
+
export type RequiredSingle = DetailedType;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* properties 必传(联合)类型
|
|
10
10
|
*/
|
|
11
|
-
export type RequiredUnion
|
|
12
|
-
type:
|
|
13
|
-
optionalTypes:
|
|
11
|
+
export type RequiredUnion = {
|
|
12
|
+
type: DetailedType;
|
|
13
|
+
optionalTypes: DetailedType[];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* properties 必传类型
|
|
18
18
|
*/
|
|
19
|
-
export type RequiredType
|
|
19
|
+
export type RequiredType = RequiredUnion | RequiredSingle;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* properties 选传类型
|
|
23
23
|
*/
|
|
24
|
-
export type OptionalType
|
|
25
|
-
type:
|
|
26
|
-
value:
|
|
27
|
-
optionalTypes?:
|
|
24
|
+
export type OptionalType = {
|
|
25
|
+
type: DetailedType;
|
|
26
|
+
value: unknown;
|
|
27
|
+
optionalTypes?: DetailedType[];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Properties 字段类型
|
|
32
32
|
*/
|
|
33
|
-
export type PropertiesTypes
|
|
33
|
+
export type PropertiesTypes = OptionalType | RequiredType;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* RootComponent API properties 字段约束
|
|
37
37
|
*/
|
|
38
|
-
export type PropertiesConstraint
|
|
38
|
+
export type PropertiesConstraint = Record<string, PropertiesTypes>;
|
|
@@ -13,7 +13,7 @@ export type PropertiesOption<
|
|
|
13
13
|
= // DuplicateFieldCheck extends PropertyKey = "",
|
|
14
14
|
{
|
|
15
15
|
/**
|
|
16
|
-
* 可通过 as
|
|
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 {
|
|
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
|
|
15
|
+
} ? V extends InferDetailedType<R> ? never
|
|
16
16
|
: k
|
|
17
17
|
: never
|
|
18
18
|
]: { value: () => "⚠️类型错误⚠️" };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
17
|
+
type: String as DetailedType<"male" | "female">, // 同类字面量联合类型
|
|
18
18
|
value: "male",
|
|
19
19
|
},
|
|
20
20
|
optional_tuple: {
|
|
21
|
-
type: Array as unknown as
|
|
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
|
|
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
|
|
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 使用
|
|
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
|
|
84
|
+
xxx: Object as DetailedType<{ dd: Foo }>,
|
|
85
85
|
user: {
|
|
86
|
-
type: Object as
|
|
86
|
+
type: Object as DetailedType<Foo>,
|
|
87
87
|
value: { name: "zhao" },
|
|
88
88
|
},
|
|
89
89
|
},
|
|
@@ -93,3 +93,17 @@ RootComponent()({
|
|
|
93
93
|
},
|
|
94
94
|
},
|
|
95
95
|
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 对象类型字面量类型可验证通过。
|
|
99
|
+
*/
|
|
100
|
+
type obj = { gender: "male" | "femal" };
|
|
101
|
+
|
|
102
|
+
RootComponent()({
|
|
103
|
+
properties: {
|
|
104
|
+
obj: {
|
|
105
|
+
type: Object as DetailedType<obj>,
|
|
106
|
+
value: { gender: "male" },
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
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
|
|
34
|
-
union_str: String as
|
|
35
|
-
union_num: Number as
|
|
36
|
-
union_bool: Boolean as
|
|
37
|
-
union_arr: Array as
|
|
38
|
-
union_obj: Object as
|
|
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
|
|
51
|
-
optionalTypes: [Number as
|
|
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
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
26
|
+
type: String as DetailedType<"male" | "female">,
|
|
27
27
|
value: "male" as const,
|
|
28
28
|
},
|
|
29
29
|
optional_obj: {
|
|
30
|
-
type: Object as
|
|
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
|
|
38
|
+
type: Object as DetailedType<Mock_User | null>, // 可选类型定义null默认值方可为null
|
|
39
39
|
value: null,
|
|
40
40
|
},
|
|
41
41
|
} satisfies Record<string, OptionalType>;
|
|
@@ -77,17 +77,10 @@ type RootComponentOptions<
|
|
|
77
77
|
|
|
78
78
|
type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | ComponentDoc> = {
|
|
79
79
|
<
|
|
80
|
-
Literal extends
|
|
81
|
-
| string
|
|
82
|
-
| number
|
|
83
|
-
| boolean
|
|
84
|
-
| null
|
|
85
|
-
| Literal[]
|
|
86
|
-
| object,
|
|
87
80
|
// TEvents 不能有默认值 {} 会引起事件参数类型(e)失效
|
|
88
81
|
TEvents extends EventsConstraint<TReceivedComponentDoc>,
|
|
89
82
|
TIsPage extends boolean = false,
|
|
90
|
-
TProperties extends PropertiesConstraint
|
|
83
|
+
const TProperties extends PropertiesConstraint = {},
|
|
91
84
|
TData extends object = {},
|
|
92
85
|
TStore extends StoreConstraint = {},
|
|
93
86
|
TComputed extends ComputedConstraint = {},
|
|
@@ -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,
|
|
119
|
-
data: {
|
|
120
|
-
aaa_xxx: 123,
|
|
121
|
-
},
|
|
124
|
+
SubComponent<Root, $aaa>()({
|
|
122
125
|
computed: {
|
|
123
126
|
aaa_num(): number {
|
|
124
|
-
return this.data.
|
|
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 {
|
|
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 {
|
|
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
|
+
>;
|