annil 1.5.11 → 1.5.13
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 +14 -0
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +2 -1
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +1 -1
- package/dist/api/SubComponent/SubInstance/SubInstance.d.ts +1 -1
- package/dist/api/SubComponent/index.d.ts +2 -2
- package/dist/types/Replace.d.ts +8 -0
- package/dist/types/Replace.js +2 -0
- package/dist/types/Replace.js.map +1 -0
- package/package.json +1 -1
- package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +3 -1
- package/src/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.ts +8 -1
- package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +8 -0
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +23 -0
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +2 -2
- package/src/api/SubComponent/SubData/test/normal.test.ts +16 -0
- package/src/api/SubComponent/SubInstance/SubInstance.ts +2 -2
- package/src/api/SubComponent/index.ts +3 -3
- package/src/types/Replace.ts +24 -0
- package/dist/types/AssignValues.d.ts +0 -9
- package/dist/types/AssignValues.js +0 -2
- package/dist/types/AssignValues.js.map +0 -1
- package/src/types/AssignValues.ts +0 -26
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.13](https://github.com/missannil/annil/compare/v1.5.12...v1.5.13) (2024-01-12)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* 修改自定义事件detail类型为ReadOnlyDeep,以便调用时可传入实例中的data类型(都是ReadOnlyDeep的) ([428710e](https://github.com/missannil/annil/commit/428710ea84717c45361d1e6c9c7db46c693026a9))
|
|
13
|
+
|
|
14
|
+
## [1.5.12](https://github.com/missannil/annil/compare/v1.5.11...v1.5.12) (2024-01-12)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* setData时data中的数据类型不是组件类型的错误 ([871ac43](https://github.com/missannil/annil/commit/871ac439d1786cb74fb752e353a1f953d11de780))
|
|
20
|
+
|
|
7
21
|
## [1.5.11](https://github.com/missannil/annil/compare/v1.5.10...v1.5.11) (2024-01-08)
|
|
8
22
|
|
|
9
23
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
1
2
|
import type { DetailedType } from "../../../types/DetailedType";
|
|
2
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
4
|
import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents, SimpleCustomeEventsList } from "./CustomEventConstraint";
|
|
4
5
|
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
5
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T
|
|
6
|
+
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? ReadonlyDeep<InferDetailedType<T>> : T extends null ? null : T extends undefined ? undefined : T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]> : never;
|
|
6
7
|
export type GetFullCustomEventsDoc<T extends FullCustomEvents> = GetShortCustomEventsDoc<T["detail"]> | AddTagForCustomEventsDoc<T["options"]>;
|
|
7
8
|
export type GetCustomEventDoc<T extends CustomEventConstraint> = {
|
|
8
9
|
[k in keyof T]: T[k] extends ShortCustomeEvents ? GetShortCustomEventsDoc<T[k]> : GetShortCustomEventsDoc<T[k]["detail"]> | AddTagForCustomEventsDoc<T[k]["options"]>;
|
|
@@ -7,7 +7,7 @@ import type { WMComponentInstance, WMInstanceMethods, WMPageInstance } from "../
|
|
|
7
7
|
import type { IInjectData, IInjectMethods } from "../../InstanceInject/instanceConfig";
|
|
8
8
|
import type { CustomEventMethods } from "./CustomEventMethods";
|
|
9
9
|
import type { CustomSetData } from "./CustomSetData";
|
|
10
|
-
export type RootComponentInstance<TIsPage extends boolean, TMethods extends object,
|
|
10
|
+
export type RootComponentInstance<TIsPage extends boolean, TMethods extends object, TDataForSetData extends object, AllData extends object, CustomEventsDoc extends object, StoreDoc extends object> = IfExtends<false, TIsPage, WMComponentInstance, WMPageInstance> & Omit<WMInstanceMethods<{}>, "setData"> & CustomSetData<TDataForSetData> & IfExtends<{}, StoreDoc, unknown, {
|
|
11
11
|
disposer: {
|
|
12
12
|
[k in keyof StoreDoc]: IReactionDisposer;
|
|
13
13
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RootComponentInstance } from "../../RootComponent/Instance/RootComponentInstance";
|
|
2
|
-
export type SubInstance<TAllMethods extends object,
|
|
2
|
+
export type SubInstance<TAllMethods extends object, TDataForSetData extends object, AllData extends object, AllCustomEventsDoc extends object, SubStoreDoc extends object> = RootComponentInstance<false, TAllMethods, TDataForSetData, AllData, AllCustomEventsDoc, SubStoreDoc>;
|
|
@@ -5,8 +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 { AssignValues } from "../../types/AssignValues";
|
|
9
8
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
9
|
+
import type { Replace } from "../../types/Replace";
|
|
10
10
|
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
11
11
|
import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
|
|
12
12
|
import type { DataConstraint } from "../RootComponent/Data/DataConstraint";
|
|
@@ -35,7 +35,7 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
|
|
|
35
35
|
import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
|
|
36
36
|
import type { SubStoreOption } from "./SubStore/SubStoreOption";
|
|
37
37
|
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"], SubDataDoc, AllRootDataDoc &
|
|
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>>;
|
|
39
39
|
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
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
41
|
[k in keyof TSubStore]: ReturnType<TSubStore[k] & {}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
2
|
+
type _Replace<Target, Source, DifferentKeys extends keyof Target, SameKey extends keyof Source> = ComputeIntersection<{
|
|
3
|
+
[k in DifferentKeys]: Target[k];
|
|
4
|
+
} & {
|
|
5
|
+
[k in SameKey]: Source[k];
|
|
6
|
+
}>;
|
|
7
|
+
export type Replace<Target extends object, Source extends object> = _Replace<Target, Source, Exclude<keyof Target, keyof Source>, Extract<keyof Target, keyof Source>>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Replace.js","sourceRoot":"","sources":["../../src/types/Replace.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
1
2
|
import type { DetailedType } from "../../../types/DetailedType";
|
|
2
3
|
import type { InferDetailedType } from "../../../types/InferDetailedType";
|
|
3
4
|
import type {
|
|
@@ -8,7 +9,8 @@ import type {
|
|
|
8
9
|
} from "./CustomEventConstraint";
|
|
9
10
|
import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
|
|
10
11
|
|
|
11
|
-
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType
|
|
12
|
+
export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType
|
|
13
|
+
? ReadonlyDeep<InferDetailedType<T>>
|
|
12
14
|
: T extends null ? null
|
|
13
15
|
: T extends undefined ? undefined
|
|
14
16
|
: T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]>
|
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
type CapturePhaseComposedExpected,
|
|
10
10
|
type CapturePhaseExpected,
|
|
11
11
|
} from "./GetFullEventDoc.test";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type ListExpected,
|
|
14
|
+
type NullExpected,
|
|
15
|
+
type ObjExpected,
|
|
16
|
+
type StrExpected,
|
|
17
|
+
type UnionStrExpected,
|
|
18
|
+
} from "./GetShortEventDoc.test";
|
|
13
19
|
import { mock_customEvents } from "./normal.test";
|
|
14
20
|
|
|
15
21
|
type Mock_CustomEventsDoc = GetCustomEventDoc<typeof mock_customEvents>;
|
|
@@ -20,6 +26,7 @@ export type Mock_CustomEventsDocExpected = {
|
|
|
20
26
|
nothing: undefined;
|
|
21
27
|
unionStr: UnionStrExpected;
|
|
22
28
|
union: ListExpected;
|
|
29
|
+
obj: ObjExpected;
|
|
23
30
|
bubbles: bubblesExpected;
|
|
24
31
|
capturePhase: CapturePhaseExpected;
|
|
25
32
|
bubbles_capturePhase: BubblesCapturePhaseExpected;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
4
|
+
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
3
5
|
import type { GetShortCustomEventsDoc } from "../GetCustomEventDoc";
|
|
4
6
|
import { mock_shortCustomEvents } from "./normal.test";
|
|
5
7
|
|
|
@@ -26,3 +28,9 @@ type ListResult = GetShortCustomEventsDoc<typeof mock_shortCustomEvents["union"]
|
|
|
26
28
|
export type ListExpected = string | 0 | 1 | 2 | null;
|
|
27
29
|
|
|
28
30
|
Checking<ListResult, ListExpected, Test.Pass>;
|
|
31
|
+
|
|
32
|
+
type ObjResult = GetShortCustomEventsDoc<typeof mock_shortCustomEvents["obj"]>;
|
|
33
|
+
|
|
34
|
+
export type ObjExpected = ReadonlyDeep<Mock_User>;
|
|
35
|
+
|
|
36
|
+
Checking<ObjResult, ObjExpected, Test.Pass>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
+
import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
|
|
2
3
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
4
|
+
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
3
5
|
import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents } from "../CustomEventConstraint";
|
|
4
6
|
import type {
|
|
5
7
|
Bubbles,
|
|
@@ -19,6 +21,7 @@ export const mock_shortCustomEvents = {
|
|
|
19
21
|
null: null,
|
|
20
22
|
unionStr: String as DetailedType<"male" | "female">,
|
|
21
23
|
union: [String, Number as DetailedType<0 | 1 | 2>, null],
|
|
24
|
+
obj: Object as DetailedType<Mock_User>,
|
|
22
25
|
} satisfies Record<string, ShortCustomeEvents>;
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -68,6 +71,7 @@ type RootDoc = {
|
|
|
68
71
|
nothing: undefined;
|
|
69
72
|
unionStr: "male" | "female";
|
|
70
73
|
union: string | 0 | 1 | 2 | null;
|
|
74
|
+
obj: ReadonlyDeep<Mock_User>;
|
|
71
75
|
// 带options字段 通过联合类型加入。
|
|
72
76
|
bubbles: string | Bubbles;
|
|
73
77
|
capturePhase: null | Capture;
|
|
@@ -92,3 +96,22 @@ const rootDocNoFields = RootComponent()({});
|
|
|
92
96
|
|
|
93
97
|
// 3. 无customEvents字段时,Doc中无customEvents字段
|
|
94
98
|
Checking<typeof rootDocNoFields, {}, Test.Pass>;
|
|
99
|
+
|
|
100
|
+
// 4 实例中的对象数组都是readOnlyDeep类型,可以传递给自定义做参数
|
|
101
|
+
RootComponent()({
|
|
102
|
+
properties: {
|
|
103
|
+
obj: Object as DetailedType<Mock_User>,
|
|
104
|
+
},
|
|
105
|
+
data: {
|
|
106
|
+
obj1: {} as Mock_User,
|
|
107
|
+
_ddd: {} as Mock_User,
|
|
108
|
+
},
|
|
109
|
+
customEvents: mock_customEvents,
|
|
110
|
+
events: {
|
|
111
|
+
ddd() {
|
|
112
|
+
this.obj(this.data.obj!);
|
|
113
|
+
|
|
114
|
+
this.obj(this.data.obj1);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
@@ -11,7 +11,7 @@ import type { CustomSetData } from "./CustomSetData";
|
|
|
11
11
|
export type RootComponentInstance<
|
|
12
12
|
TIsPage extends boolean,
|
|
13
13
|
TMethods extends object,
|
|
14
|
-
|
|
14
|
+
TDataForSetData extends object,
|
|
15
15
|
AllData extends object,
|
|
16
16
|
CustomEventsDoc extends object,
|
|
17
17
|
StoreDoc extends object,
|
|
@@ -21,7 +21,7 @@ export type RootComponentInstance<
|
|
|
21
21
|
// 官方实例方法去除setData,因其类型宽泛
|
|
22
22
|
& Omit<WMInstanceMethods<{}>, "setData">
|
|
23
23
|
// 加入自定义setData方法
|
|
24
|
-
& CustomSetData<
|
|
24
|
+
& CustomSetData<TDataForSetData>
|
|
25
25
|
& IfExtends<{}, StoreDoc, unknown, {
|
|
26
26
|
disposer: { [k in keyof StoreDoc]: IReactionDisposer };
|
|
27
27
|
}>
|
|
@@ -65,3 +65,19 @@ SubComponent<{}, CompDoc>()({
|
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
// data建立的类型在setData时为组件类型
|
|
70
|
+
SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
71
|
+
data: {
|
|
72
|
+
aaa_obj: null,
|
|
73
|
+
},
|
|
74
|
+
lifetimes: {
|
|
75
|
+
attached() {
|
|
76
|
+
Checking<typeof this.data.aaa_obj, ReadonlyDeep<Mock_User | null>, Test.Pass>;
|
|
77
|
+
|
|
78
|
+
this.setData({
|
|
79
|
+
aaa_obj: {} as Mock_User, // aaa_obj 类型为 Mock_User | null 而非 null
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
@@ -2,8 +2,8 @@ import type { RootComponentInstance } from "../../RootComponent/Instance/RootCom
|
|
|
2
2
|
|
|
3
3
|
export type SubInstance<
|
|
4
4
|
TAllMethods extends object,
|
|
5
|
-
|
|
5
|
+
TDataForSetData extends object,
|
|
6
6
|
AllData extends object,
|
|
7
7
|
AllCustomEventsDoc extends object,
|
|
8
8
|
SubStoreDoc extends object,
|
|
9
|
-
> = RootComponentInstance<false, TAllMethods,
|
|
9
|
+
> = RootComponentInstance<false, TAllMethods, TDataForSetData, AllData, AllCustomEventsDoc, SubStoreDoc>;
|
|
@@ -6,8 +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 { AssignValues } from "../../types/AssignValues";
|
|
10
9
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
10
|
+
import type { Replace } from "../../types/Replace";
|
|
11
11
|
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
12
12
|
import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
|
|
13
13
|
import type { DataConstraint } from "../RootComponent/Data/DataConstraint";
|
|
@@ -95,8 +95,8 @@ type Options<
|
|
|
95
95
|
& ThisType<
|
|
96
96
|
SubInstance<
|
|
97
97
|
SubMethodsDoc & RootDoc["methods"],
|
|
98
|
-
SubDataDoc,
|
|
99
|
-
AllRootDataDoc &
|
|
98
|
+
Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>,
|
|
99
|
+
AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>,
|
|
100
100
|
RootDoc["customEvents"] & {},
|
|
101
101
|
SubStoreDoc
|
|
102
102
|
>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
2
|
+
|
|
3
|
+
type _Replace<Target, Source, DifferentKeys extends keyof Target, SameKey extends keyof Source> = ComputeIntersection<
|
|
4
|
+
& { [k in DifferentKeys]: Target[k] }
|
|
5
|
+
& { [k in SameKey]: Source[k] }
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Target与Source相同的key类型替换为Source的类型
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* type obj = { a: "a"; b: "b"; c: boolean };
|
|
13
|
+
* type obj2 = { a: number; b: string; d: number };
|
|
14
|
+
* type test = Replace<obj, obj2>;
|
|
15
|
+
* // test = { a: number; b: string; c: boolean}
|
|
16
|
+
* type test1 = Replace<{}, obj2>; // {}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type Replace<Target extends object, Source extends object> = _Replace<
|
|
20
|
+
Target,
|
|
21
|
+
Source,
|
|
22
|
+
Exclude<keyof Target, keyof Source>,
|
|
23
|
+
Extract<keyof Target, keyof Source>
|
|
24
|
+
>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
-
type _AssignValues<Target, Source, UniqueKey extends keyof Target> = ComputeIntersection<{
|
|
4
|
-
[k in UniqueKey]: Target[k];
|
|
5
|
-
} & {
|
|
6
|
-
[k in Exclude<keyof Target, UniqueKey>]: Source[k];
|
|
7
|
-
}>;
|
|
8
|
-
export type AssignValues<Target, Source> = IfExtends<unknown, Target, unknown, _AssignValues<Target, Source, Exclude<keyof Target, keyof Source>>>;
|
|
9
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AssignValues.js","sourceRoot":"","sources":["../../src/types/AssignValues.ts"],"names":[],"mappings":""}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
-
|
|
4
|
-
type _AssignValues<Target, Source, UniqueKey extends keyof Target> = ComputeIntersection<
|
|
5
|
-
& { [k in UniqueKey]: Target[k] }
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
& { [k in Exclude<keyof Target, UniqueKey>]: Source[k] }
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Target与Source相同的key类型变为Source的类型
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* type obj = { a: "a"; b: "b"; c: boolean };
|
|
15
|
-
* type obj2 = { a: number; b: string; d: number };
|
|
16
|
-
* type test = AssignValues<obj, obj2>;
|
|
17
|
-
* // test = { a: number; b: string; c: boolean}
|
|
18
|
-
* type test1 = AssignValues<unknown, obj2>; // unknown
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export type AssignValues<Target, Source> = IfExtends<
|
|
22
|
-
unknown,
|
|
23
|
-
Target,
|
|
24
|
-
unknown,
|
|
25
|
-
_AssignValues<Target, Source, Exclude<keyof Target, keyof Source>>
|
|
26
|
-
>;
|