annil 1.12.7 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/api/ChunkComponent/ChunkStore/ChunkStoreOption.d.ts +2 -1
- package/dist/api/CustomComponent/CustomStore/CustomStoreConstraint.d.ts +3 -2
- package/dist/api/CustomComponent/CustomStore/CustomStoreOption.d.ts +1 -3
- package/dist/api/CustomComponent/index.d.ts +2 -1
- package/dist/api/CustomComponent/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js +4 -19
- package/dist/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.js.map +1 -1
- package/dist/api/RootComponent/Store/StoreConstraint.d.ts +1 -5
- package/dist/api/RootComponent/Store/StoreOption.d.ts +1 -12
- package/dist/thirdLib/vant/Popup.d.ts +1 -1
- package/dist/thirdLib/wm/Textarea.d.ts +1 -1
- package/dist/thirdLib/wm/swiper.d.ts +1 -1
- package/dist/types/AddNullForObject.d.ts +2 -0
- package/dist/types/AddNullForObject.js +2 -0
- package/dist/types/AddNullForObject.js.map +1 -0
- package/dist/types/Replace.d.ts +8 -0
- package/dist/types/Replace.js +2 -0
- package/dist/types/Replace.js.map +1 -0
- package/dist/utils/nonNullable.d.ts +1 -1
- package/dist/utils/nonNullable.js +2 -2
- package/dist/utils/nonNullable.js.map +1 -1
- package/package.json +1 -1
- package/src/api/ChunkComponent/ChunkStore/ChunkStoreOption.ts +2 -1
- package/src/api/ChunkComponent/ChunkStore/test/error.test.ts +3 -31
- package/src/api/ChunkComponent/ChunkStore/test/normal.test.ts +40 -41
- package/src/api/CustomComponent/CustomData/test/normal.test.ts +7 -4
- package/src/api/CustomComponent/CustomStore/CustomStoreConstraint.ts +3 -2
- package/src/api/CustomComponent/CustomStore/CustomStoreOption.ts +0 -2
- package/src/api/CustomComponent/CustomStore/test/error.test.ts +6 -46
- package/src/api/CustomComponent/CustomStore/test/normal.test.ts +0 -45
- package/src/api/CustomComponent/index.ts +5 -4
- package/src/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.ts +5 -20
- package/src/api/RootComponent/Events/EventsOption.ts +2 -2
- package/src/api/RootComponent/Store/StoreConstraint.ts +1 -7
- package/src/api/RootComponent/Store/StoreOption.ts +6 -40
- package/src/api/RootComponent/Store/test/error.test.ts +3 -38
- package/src/api/RootComponent/Store/test/normal.test.ts +0 -46
- package/src/thirdLib/vant/Popup.ts +1 -1
- package/src/thirdLib/wm/Textarea.ts +1 -1
- package/src/thirdLib/wm/swiper.test.ts +24 -0
- package/src/thirdLib/wm/swiper.ts +1 -1
- package/src/types/CreateComponentType.ts +2 -2
- package/src/types/ExtendComponentType.ts +5 -5
- package/src/utils/nonNullable.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
* 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
|
|
6
6
|
|
|
7
|
+
## [1.13.0](https://github.com/missannil/annil/compare/v1.12.7...v1.13.0) (2026-03-22)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* 去除store的对象写法 ([9f2d50c](https://github.com/missannil/annil/commit/9f2d50c68fadda1ef166fcbedb2890461650c687))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* nonNullable.ts 增加第二个错误信息参数,第三方库和wm库类型中customEvents字段变为events ([a38e8c5](https://github.com/missannil/annil/commit/a38e8c5f14237884c338d57bb11fcee1538b57fe))
|
|
18
|
+
* 使用Replace泛型解决实例和setData中使用data字段推导类型为字面量的问题 ([9a2cf3d](https://github.com/missannil/annil/commit/9a2cf3da30d2b0a5ade1e22800f34df97cce7896))
|
|
19
|
+
|
|
7
20
|
## [1.12.7](https://github.com/missannil/annil/compare/v1.12.7...v1.12.7) (2026-03-19)
|
|
8
21
|
|
|
9
22
|
|
|
@@ -2,7 +2,8 @@ import type { G } from "hry-types";
|
|
|
2
2
|
import type { Validators } from "../../../types/Validators";
|
|
3
3
|
import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
|
|
4
4
|
import type { ValidatorPrefix } from "../ChunkData/validatePrefix";
|
|
5
|
-
|
|
5
|
+
import type { ChunkStoreConstraint } from "./ChunkStoreConstraint";
|
|
6
|
+
export type ChunkStoreOption<TStore extends ChunkStoreConstraint, TDuplicateKeys extends PropertyKey, Prefix extends string> = {
|
|
6
7
|
store?: TStore & Validators<[
|
|
7
8
|
G.DuplicateFieldValidator<TStore, TDuplicateKeys, "字段重复">,
|
|
8
9
|
ValidatorPrefix<TStore, Prefix>,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
2
|
+
import type { Getter } from "../../RootComponent/Store/StoreConstraint";
|
|
2
3
|
export type CustomStoreConstraint<PropertyDoc extends object, legal extends object> = {
|
|
3
|
-
[k in keyof legal]?: Getter<PropertyDoc,
|
|
4
|
+
[k in keyof legal]?: Getter<PropertyDoc, AddNullForObject<legal[k]>>;
|
|
4
5
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
2
|
import type { Validators } from "../../../types/Validators";
|
|
3
|
-
import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
|
|
4
3
|
export type CustomStoreOption<TStore extends object, legalKeys extends PropertyKey> = {
|
|
5
4
|
store?: TStore & Validators<[
|
|
6
|
-
G.IllegalFieldValidator<TStore, legalKeys, 0, "", "与inherit和data字段重复或前缀错误"
|
|
7
|
-
TypeValidator<TStore>
|
|
5
|
+
G.IllegalFieldValidator<TStore, legalKeys, 0, "", "与inherit和data字段重复或前缀错误">
|
|
8
6
|
]>;
|
|
9
7
|
};
|
|
@@ -5,6 +5,7 @@ import type { Extra } from "../../types/Extra";
|
|
|
5
5
|
import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
|
|
6
6
|
import type { InnerFields } from "../../types/InnerData";
|
|
7
7
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
8
|
+
import type { Replace } from "../../types/Replace";
|
|
8
9
|
import type { ReplacePrefix } from "../../types/ReplacePrefix";
|
|
9
10
|
import type { UnionToComma } from "../../types/UnionToComma.test";
|
|
10
11
|
import type { ComponentDoc } from "../DefineComponent/returnType/ComponentDoc";
|
|
@@ -38,7 +39,7 @@ type Options<RootDoc extends RootComponentDefinition, IsPage extends boolean, Cu
|
|
|
38
39
|
[k in keyof NoInfer<TSubStore>]: k extends keyof (AllRootDataDoc & SubDataDoc) ? never : k extends Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> ? k : k extends InnerFields<Prefix> ? k : never;
|
|
39
40
|
}[keyof NoInfer<TSubStore>]> & CustomComputedOption<TSubComputed, {
|
|
40
41
|
[k in keyof NoInfer<TSubComputed>]: k extends keyof (AllRootDataDoc & SubDataDoc & SubStoreDoc) ? never : k extends Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> ? k : k extends InnerFields<Prefix> ? k : never;
|
|
41
|
-
}[keyof NoInfer<TSubComputed>]> & CustomEventsOption<TEvents, SubEventsDoc, keyof CustomEventsConstraint<CurrentCompDoc>> & CustomMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["events"] & SubEventsDoc)> & CustomPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & CustomLifetimesOption & CustomWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & CustomObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<CustomInstance<SubMethodsDoc & RootDoc["methods"], SubDataDoc, AllRootDataDoc & SubDataDoc & SubComputedDoc & SubStoreDoc, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
|
|
42
|
+
}[keyof NoInfer<TSubComputed>]> & CustomEventsOption<TEvents, SubEventsDoc, keyof CustomEventsConstraint<CurrentCompDoc>> & CustomMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["events"] & SubEventsDoc)> & CustomPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & CustomLifetimesOption & CustomWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & CustomObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<CustomInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
|
|
42
43
|
type CustomComponentConstructor<TRootDoc extends RootComponentDefinition, 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 & {
|
|
43
44
|
properties: Extra<CurrentPrefix>;
|
|
44
45
|
}, ReplacePrefix<TOriginalCompDoc & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/CustomComponent/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/CustomComponent/index.ts"],"names":[],"mappings":"AA4SA,MAAM,UAAU,eAAe;IAW7B,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,CAAQ,CAAC;AAC5C,CAAC"}
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
function isGetter(value) {
|
|
2
|
-
return typeof value === "function";
|
|
3
|
-
}
|
|
4
1
|
export function reactionRegister(storeConfig) {
|
|
5
2
|
const { comparer, reaction, toJS } = require("mobx");
|
|
6
3
|
this.disposer = {};
|
|
7
4
|
const peddingSetData = {};
|
|
8
5
|
for (const key in storeConfig) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value = itemConfig(this.data);
|
|
14
|
-
if (value === undefined) {
|
|
15
|
-
throw new Error(`store配置中 ${key} 字段的 函数值不可为undefined`);
|
|
16
|
-
}
|
|
17
|
-
getter = itemConfig;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (itemConfig.getter(this.data) !== undefined) {
|
|
21
|
-
throw new Error(`store配置中 ${key}字段的配置对象中getter函数值不为undefined`);
|
|
22
|
-
}
|
|
23
|
-
getter = itemConfig.getter;
|
|
24
|
-
value = itemConfig.default;
|
|
6
|
+
const getter = storeConfig[key];
|
|
7
|
+
const value = getter(this.data);
|
|
8
|
+
if (value === undefined) {
|
|
9
|
+
throw new Error(`store配置中 ${key} 字段的返回值不可为undefined`);
|
|
25
10
|
}
|
|
26
11
|
peddingSetData[key] = toJS(value);
|
|
27
12
|
this.disposer[key] = reaction(() => getter(this.data), (value) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactionRegister.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"reactionRegister.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/handleStore/reactionRegister.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,gBAAgB,CAAiB,WAA4B;IAE3E,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAgB,CAAC;IAEpE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACnB,MAAM,cAAc,GAA4B,EAAE,CAAC;IACnD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,YAAY,GAAG,qBAAqB,CAAC,CAAC;QACxD,CAAC;QAED,cAAc,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAC3B,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EACvB,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC;gBACX,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;aACnB,CAAC,CAAC;QACL,CAAC,EACD;YACE,MAAM,EAAE,QAAQ,CAAC,UAAU;SAC5B,CACF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
export type Getter<T extends object = object, R = unknown> = (data: T) => R;
|
|
2
|
-
export type
|
|
3
|
-
getter: Getter<T, R | undefined>;
|
|
4
|
-
default: unknown;
|
|
5
|
-
};
|
|
6
|
-
export type StoreConstraint<T extends object = object> = Record<string, Getter<T> | WithDefault<T>>;
|
|
2
|
+
export type StoreConstraint<T extends object = object> = Record<string, Getter<T>>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
2
|
import type { As } from "hry-types/src/Any/As";
|
|
3
3
|
import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
4
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
5
|
-
import type { IsPureObject } from "hry-types/src/Any/IsPureObject";
|
|
6
4
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
7
5
|
import type { Validators } from "../../../types/Validators";
|
|
8
6
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
@@ -13,14 +11,5 @@ export type StoreOption<TStore extends StoreConstraint, TDuplicateKeys extends P
|
|
|
13
11
|
]>;
|
|
14
12
|
};
|
|
15
13
|
export type TypeValidator<TStore, Result = {
|
|
16
|
-
[k in keyof TStore]: TStore[k]
|
|
17
|
-
getter: (...arg: unknown[]) => infer R;
|
|
18
|
-
default: infer D;
|
|
19
|
-
} ? IfContains<R, undefined, IfExtends<IsPureObject<Exclude<R, undefined>>, true, IfExtends<D, Exclude<R, undefined> | null, unknown, {
|
|
20
|
-
default: () => "⚠️类型错误⚠️";
|
|
21
|
-
}>, IfExtends<D, Exclude<R, undefined>, unknown, {
|
|
22
|
-
default: () => "⚠️类型错误⚠️";
|
|
23
|
-
}>>, {
|
|
24
|
-
getter: () => "⚠️类型不包含undefined⚠️ ";
|
|
25
|
-
}> : IfContains<ReturnType<As<TStore[k], Func>>, undefined, () => "⚠️类型包含undefined,应写成对象形式⚠️", unknown>;
|
|
14
|
+
[k in keyof TStore]: IfContains<ReturnType<As<TStore[k], Func>>, undefined, () => "⚠️返回类型中不可以包含undefined⚠️", unknown>;
|
|
26
15
|
}> = Record<keyof TStore, unknown> extends Result ? unknown : Result;
|
|
@@ -26,7 +26,7 @@ export type Swiper = CreateComponentType<"swiper", {
|
|
|
26
26
|
displayMultipleItems?: number;
|
|
27
27
|
easingFunction?: "defaultValue" | "linear" | "easeInCubic" | "easeOutCubic" | "easeInOutCubic";
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
events: {
|
|
30
30
|
change: ChangeEventDetail;
|
|
31
31
|
transition: {
|
|
32
32
|
dx: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddNullForObject.js","sourceRoot":"","sources":["../../src/types/AddNullForObject.ts"],"names":[],"mappings":""}
|
|
@@ -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":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
2
|
-
export declare function nonNullable<T>(value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined"
|
|
2
|
+
export declare function nonNullable<T>(value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined">, message?: string): NonNullable<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function nonNullable(value) {
|
|
1
|
+
export function nonNullable(value, message) {
|
|
2
2
|
if (value === null || value === undefined) {
|
|
3
|
-
throw new Error(`${value} should not be null or undefined`);
|
|
3
|
+
throw new Error(message !== null && message !== void 0 ? message : `${value} should not be null or undefined`);
|
|
4
4
|
}
|
|
5
5
|
return value;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nonNullable.js","sourceRoot":"","sources":["../../src/utils/nonNullable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nonNullable.js","sourceRoot":"","sources":["../../src/utils/nonNullable.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,WAAW,CACzB,KAAsE,EACtE,OAAgB;IAGhB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,GAAG,KAAK,kCAAkC,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,KAAuB,CAAC;AACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,9 +2,10 @@ import type { G } from "hry-types";
|
|
|
2
2
|
import type { Validators } from "../../../types/Validators";
|
|
3
3
|
import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
|
|
4
4
|
import type { ValidatorPrefix } from "../ChunkData/validatePrefix";
|
|
5
|
+
import type { ChunkStoreConstraint } from "./ChunkStoreConstraint";
|
|
5
6
|
|
|
6
7
|
export type ChunkStoreOption<
|
|
7
|
-
TStore extends
|
|
8
|
+
TStore extends ChunkStoreConstraint,
|
|
8
9
|
TDuplicateKeys extends PropertyKey,
|
|
9
10
|
Prefix extends string,
|
|
10
11
|
> = {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { observable } from "mobx";
|
|
2
1
|
import { ChunkComponent } from "../..";
|
|
3
2
|
import type { Mock_RootDoc } from "./mock";
|
|
4
3
|
|
|
@@ -28,37 +27,10 @@ ChunkComponent<Mock_RootDoc, "slot">()({
|
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
name: string;
|
|
33
|
-
age?: number;
|
|
34
|
-
};
|
|
35
|
-
type AllGoods = Record<string, User[] | undefined>;
|
|
36
|
-
const M_User = observable({
|
|
37
|
-
allUser: {
|
|
38
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
39
|
-
categoryB: [{ name: "zhao" }],
|
|
40
|
-
} as AllGoods,
|
|
41
|
-
});
|
|
42
|
-
|
|
30
|
+
// 4. 返回类型错误
|
|
43
31
|
ChunkComponent<{ properties: { categoryId: string } }>()({
|
|
44
32
|
store: {
|
|
45
|
-
// @ts-expect-error 1
|
|
46
|
-
categoryList: (
|
|
47
|
-
|
|
48
|
-
_categoryList: {
|
|
49
|
-
// @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
|
|
50
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[],
|
|
51
|
-
default: 0,
|
|
52
|
-
},
|
|
53
|
-
_categoryList1: {
|
|
54
|
-
getter: (data) => M_User.allUser[data.categoryId],
|
|
55
|
-
// @ts-expect-error 3 默认值应该为[]
|
|
56
|
-
default: 0,
|
|
57
|
-
},
|
|
58
|
-
_categoryList2: {
|
|
59
|
-
getter: (data) => M_User.allUser[data.categoryId]?.[0],
|
|
60
|
-
// @ts-expect-error 3 对象类型错误 namesss
|
|
61
|
-
default: { namesss: "zhao", age: 20 },
|
|
62
|
-
},
|
|
33
|
+
// @ts-expect-error 4.1 返回类型中不可以包含undefined
|
|
34
|
+
categoryList: () => undefined,
|
|
63
35
|
},
|
|
64
36
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { observable } from "mobx";
|
|
2
1
|
import { ChunkComponent } from "../..";
|
|
3
2
|
import type { Mock_RootDoc } from "./mock";
|
|
4
3
|
|
|
@@ -10,44 +9,44 @@ ChunkComponent<Mock_RootDoc, "slot">()({
|
|
|
10
9
|
},
|
|
11
10
|
});
|
|
12
11
|
|
|
13
|
-
type User = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
type AllGoods = Record<string, User[]>;
|
|
18
|
-
const M_User = observable({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
12
|
+
// type User = {
|
|
13
|
+
// name: string;
|
|
14
|
+
// age?: number;
|
|
15
|
+
// };
|
|
16
|
+
// type AllGoods = Record<string, User[]>;
|
|
17
|
+
// const M_User = observable({
|
|
18
|
+
// allUser: {
|
|
19
|
+
// categoryA: [{ name: "zhao", age: 20 }],
|
|
20
|
+
// categoryB: [{ name: "zhao" }],
|
|
21
|
+
// } as AllGoods,
|
|
22
|
+
// });
|
|
24
23
|
|
|
25
|
-
ChunkComponent<{ properties: { categoryId: string } }>()({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
24
|
+
// ChunkComponent<{ properties: { categoryId: string } }>()({
|
|
25
|
+
// data: {
|
|
26
|
+
// // categoryList:[],
|
|
27
|
+
// },
|
|
28
|
+
// store: {
|
|
29
|
+
// // 1 响应式不包含undefined时 只能写成getter函数形式
|
|
30
|
+
// categoryList: (data) => M_User.allUser[data.categoryId],
|
|
31
|
+
// // 2 响应式数据包含undefined时 只能写成对象形式
|
|
32
|
+
// _categoryList: {
|
|
33
|
+
// getter: (data) => M_User.allUser[data.categoryId][0].age,
|
|
34
|
+
// default: 0,
|
|
35
|
+
// },
|
|
36
|
+
// _categoryList1: {
|
|
37
|
+
// getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
|
|
38
|
+
// // 默认值为[]
|
|
39
|
+
// default: [],
|
|
40
|
+
// },
|
|
41
|
+
// _categoryList2: {
|
|
42
|
+
// getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
43
|
+
// // 对象类型 默认值为User类型
|
|
44
|
+
// default: { name: "zhao", age: 20 },
|
|
45
|
+
// },
|
|
46
|
+
// _categoryList3: {
|
|
47
|
+
// getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
48
|
+
// // 对象类型 默认值可以为null
|
|
49
|
+
// default: null,
|
|
50
|
+
// },
|
|
51
|
+
// },
|
|
52
|
+
// });
|
|
@@ -65,17 +65,20 @@ CustomComponent<{}, CompDoc>()({
|
|
|
65
65
|
},
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
// data
|
|
68
|
+
// 确保实例和setData中使用的data字段类型为文档中定义的类型而非data配置中的类型(data中配置的类型可能推导默认为字面量类型,通过加入Replace泛型替换为对应的文档类型。),
|
|
69
69
|
CustomComponent<{ data: { _num: number } }, CompDoc>()({
|
|
70
70
|
data: {
|
|
71
|
-
aaa_obj: null
|
|
71
|
+
aaa_obj: null, // 类型为null 而非 Mock_User | null
|
|
72
|
+
aaa_str: "a", // 类型为"a" 而非string
|
|
73
|
+
aaa_num: 123, // 类型为123 而非number
|
|
72
74
|
},
|
|
73
75
|
lifetimes: {
|
|
74
76
|
attached() {
|
|
77
|
+
// 实例中的aaa_obj类型为文档中定义的类型 Mock_User | null 而非data配置中的类型 null
|
|
75
78
|
void Checking<typeof this.data.aaa_obj, Mock_User | null, Test.Pass>;
|
|
76
|
-
|
|
79
|
+
// setData中aaa_str类型为文档中定义的类型 "a" | "b" 而非data配置中的类型 "a"
|
|
77
80
|
this.setData({
|
|
78
|
-
|
|
81
|
+
aaa_str: "b",
|
|
79
82
|
});
|
|
80
83
|
},
|
|
81
84
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
2
|
+
import type { Getter } from "../../RootComponent/Store/StoreConstraint";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 子组件Data字段约束
|
|
@@ -8,5 +9,5 @@ export type CustomStoreConstraint<
|
|
|
8
9
|
PropertyDoc extends object,
|
|
9
10
|
legal extends object,
|
|
10
11
|
> = {
|
|
11
|
-
[k in keyof legal]?: Getter<PropertyDoc,
|
|
12
|
+
[k in keyof legal]?: Getter<PropertyDoc, AddNullForObject<legal[k]>>;
|
|
12
13
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
2
|
import type { Validators } from "../../../types/Validators";
|
|
3
|
-
import type { TypeValidator } from "../../RootComponent/Store/StoreOption";
|
|
4
3
|
|
|
5
4
|
export type CustomStoreOption<TStore extends object, legalKeys extends PropertyKey> = {
|
|
6
5
|
/**
|
|
@@ -28,7 +27,6 @@ export type CustomStoreOption<TStore extends object, legalKeys extends PropertyK
|
|
|
28
27
|
"",
|
|
29
28
|
"与inherit和data字段重复或前缀错误"
|
|
30
29
|
>,
|
|
31
|
-
TypeValidator<TStore>,
|
|
32
30
|
]
|
|
33
31
|
>;
|
|
34
32
|
};
|
|
@@ -47,54 +47,14 @@ CustomComponent<{
|
|
|
47
47
|
aaa_num: () => 123,
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// 类型约束错误
|
|
51
|
+
CustomComponent<{
|
|
52
52
|
properties: {
|
|
53
|
-
|
|
53
|
+
aaa_num: number;
|
|
54
54
|
};
|
|
55
|
-
}
|
|
56
|
-
type User = {
|
|
57
|
-
name: string;
|
|
58
|
-
age?: number;
|
|
59
|
-
};
|
|
60
|
-
type AllGoods = Record<string, User[] | undefined>;
|
|
61
|
-
const M_User = observable({
|
|
62
|
-
allUser: {
|
|
63
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
64
|
-
categoryB: [{ name: "zhao" }],
|
|
65
|
-
} as AllGoods,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
CustomComponent<{ properties: { categoryId: string } }, DocText>()({
|
|
69
|
-
store: {
|
|
70
|
-
// @ts-expect-error 1 响应式包含undefined时 不可以写成getter函数形式
|
|
71
|
-
aaa_useList: (data) => M_User.allUser[data.categoryId],
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
CustomComponent<{ properties: { categoryId: string } }, DocText>()({
|
|
75
|
-
store: {
|
|
76
|
-
_aaa_categoryList: {
|
|
77
|
-
// @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
|
|
78
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[],
|
|
79
|
-
default: 0,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
CustomComponent<{ properties: { categoryId: string } }, DocText>()({
|
|
84
|
-
store: {
|
|
85
|
-
_aaa_categoryList1: {
|
|
86
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
|
|
87
|
-
// @ts-expect-error 3 默认值应该为[]
|
|
88
|
-
default: 0,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
CustomComponent<{ properties: { categoryId: string } }, DocText>()({
|
|
55
|
+
}, DocA>()({
|
|
93
56
|
store: {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// @ts-expect-error 对象类型 默认值为User类型或null namesss错误
|
|
97
|
-
default: { namesss: "zhao", age: 20 },
|
|
98
|
-
},
|
|
57
|
+
// @ts-expect-error 返回类型错误
|
|
58
|
+
aaa_num: () => undefined,
|
|
99
59
|
},
|
|
100
60
|
});
|
|
@@ -34,48 +34,3 @@ CustomComponent<{ data: { _num: number } }, DocA, "a">()({
|
|
|
34
34
|
aaaA_isReady: () => false,
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
|
-
|
|
38
|
-
type DocText = ComponentDoc<{
|
|
39
|
-
properties: {
|
|
40
|
-
aaa_useList: User[];
|
|
41
|
-
};
|
|
42
|
-
}>;
|
|
43
|
-
type User = {
|
|
44
|
-
name: string;
|
|
45
|
-
age?: number;
|
|
46
|
-
};
|
|
47
|
-
type AllGoods = Record<string, User[]>;
|
|
48
|
-
const M_User = observable({
|
|
49
|
-
allUser: {
|
|
50
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
51
|
-
categoryB: [{ name: "zhao" }],
|
|
52
|
-
} as AllGoods,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// store中getter函数第一个参数为properties的类型
|
|
56
|
-
CustomComponent<{ properties: { categoryId: string } }, DocText>()({
|
|
57
|
-
store: {
|
|
58
|
-
// 1 响应式不包含undefined时 只能写成getter函数形式
|
|
59
|
-
aaa_useList: (data) => M_User.allUser[data.categoryId],
|
|
60
|
-
// 2 响应式数据包含undefined时 只能写成对象形式
|
|
61
|
-
_aaa_categoryList: {
|
|
62
|
-
getter: (data) => M_User.allUser[data.categoryId][0].age,
|
|
63
|
-
default: 0,
|
|
64
|
-
},
|
|
65
|
-
_aaa_categoryList1: {
|
|
66
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
|
|
67
|
-
// 默认值为[]
|
|
68
|
-
default: [],
|
|
69
|
-
},
|
|
70
|
-
_aaa_categoryList2: {
|
|
71
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
72
|
-
// 对象类型 默认值为User类型
|
|
73
|
-
default: { name: "zhao", age: 20 },
|
|
74
|
-
},
|
|
75
|
-
_aaa_categoryList3: {
|
|
76
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
77
|
-
// 对象类型 默认值可以为null
|
|
78
|
-
default: null,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
@@ -5,6 +5,7 @@ import type { Extra } from "../../types/Extra";
|
|
|
5
5
|
import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
|
|
6
6
|
import type { InnerFields } from "../../types/InnerData";
|
|
7
7
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
8
|
+
import type { Replace } from "../../types/Replace";
|
|
8
9
|
import type { ReplacePrefix } from "../../types/ReplacePrefix";
|
|
9
10
|
import type { UnionToComma } from "../../types/UnionToComma.test";
|
|
10
11
|
import type { ComponentDoc } from "../DefineComponent/returnType/ComponentDoc";
|
|
@@ -149,10 +150,10 @@ type Options<
|
|
|
149
150
|
& ThisType<
|
|
150
151
|
CustomInstance<
|
|
151
152
|
SubMethodsDoc & RootDoc["methods"],
|
|
152
|
-
|
|
153
|
-
SubDataDoc,
|
|
154
|
-
|
|
155
|
-
AllRootDataDoc & SubDataDoc & SubComputedDoc & SubStoreDoc,
|
|
153
|
+
Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, // Replace目的是让setData中的类型与文档中定义的类型一致
|
|
154
|
+
// SubDataDoc,
|
|
155
|
+
AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, // Replace的目的是让实例中的类型与文档中定义的类型一致
|
|
156
|
+
// AllRootDataDoc & SubDataDoc & SubComputedDoc & SubStoreDoc,
|
|
156
157
|
NonNullable<RootDoc["customEvents"]>,
|
|
157
158
|
SubStoreDoc
|
|
158
159
|
>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type mobx from "mobx";
|
|
2
2
|
import type { Instance } from "../../../RootComponent/Instance/RootComponentInstance";
|
|
3
|
-
import type {
|
|
4
|
-
function isGetter(value: Getter | WithDefault): value is Getter {
|
|
5
|
-
return typeof value === "function";
|
|
6
|
-
}
|
|
3
|
+
import type { StoreConstraint } from "../../../RootComponent/Store/StoreConstraint";
|
|
7
4
|
export function reactionRegister(this: Instance, storeConfig: StoreConstraint) {
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
9
6
|
const { comparer, reaction, toJS } = require("mobx") as typeof mobx;
|
|
@@ -11,23 +8,11 @@ export function reactionRegister(this: Instance, storeConfig: StoreConstraint) {
|
|
|
11
8
|
this.disposer = {};
|
|
12
9
|
const peddingSetData: Record<string, unknown> = {};
|
|
13
10
|
for (const key in storeConfig) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
value = itemConfig(this.data);
|
|
19
|
-
if (value === undefined) {
|
|
20
|
-
throw new Error(`store配置中 ${key} 字段的 函数值不可为undefined`);
|
|
21
|
-
}
|
|
22
|
-
getter = itemConfig;
|
|
23
|
-
} else {
|
|
24
|
-
if (itemConfig.getter(this.data) !== undefined) {
|
|
25
|
-
throw new Error(`store配置中 ${key}字段的配置对象中getter函数值不为undefined`);
|
|
26
|
-
}
|
|
27
|
-
getter = itemConfig.getter;
|
|
28
|
-
value = itemConfig.default;
|
|
11
|
+
const getter = storeConfig[key];
|
|
12
|
+
const value = getter(this.data);
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
throw new Error(`store配置中 ${key} 字段的返回值不可为undefined`);
|
|
29
15
|
}
|
|
30
|
-
|
|
31
16
|
// 添加响应式逻辑
|
|
32
17
|
peddingSetData[key] = toJS(value);
|
|
33
18
|
this.disposer[key] = reaction(
|
|
@@ -15,14 +15,14 @@ export type EventsOption<TEvents extends object> = {
|
|
|
15
15
|
* @example B
|
|
16
16
|
* ```ts
|
|
17
17
|
* type ComponentDocA = {
|
|
18
|
-
*
|
|
18
|
+
* events: {
|
|
19
19
|
* aaa_str: string;
|
|
20
20
|
* aaa_num: number | Bubbles;
|
|
21
21
|
* };
|
|
22
22
|
* };
|
|
23
23
|
*
|
|
24
24
|
* type ComponentDocB = {
|
|
25
|
-
*
|
|
25
|
+
* events: {
|
|
26
26
|
* bbb_str: string;
|
|
27
27
|
* bbb_num: number | Capture;
|
|
28
28
|
* };
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
export type Getter<T extends object = object, R = unknown> = (data: T) => R;
|
|
2
|
-
|
|
3
|
-
export type WithDefault<T extends object = object, R = unknown> = {
|
|
4
|
-
getter: Getter<T, R | undefined>;
|
|
5
|
-
default: unknown;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type StoreConstraint<T extends object = object> = Record<string, Getter<T> | WithDefault<T>>;
|
|
2
|
+
export type StoreConstraint<T extends object = object> = Record<string, Getter<T>>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
2
|
import type { As } from "hry-types/src/Any/As";
|
|
3
3
|
import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
4
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
5
|
-
import type { IsPureObject } from "hry-types/src/Any/IsPureObject";
|
|
6
4
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
7
5
|
import type { Validators } from "../../../types/Validators";
|
|
8
6
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
@@ -45,43 +43,11 @@ export type StoreOption<
|
|
|
45
43
|
export type TypeValidator<
|
|
46
44
|
TStore,
|
|
47
45
|
Result = {
|
|
48
|
-
[k in keyof TStore]:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
R,
|
|
55
|
-
undefined,
|
|
56
|
-
// 如果包含undefined时
|
|
57
|
-
IfExtends<
|
|
58
|
-
// 是否为纯对象
|
|
59
|
-
IsPureObject<Exclude<R, undefined>>,
|
|
60
|
-
true,
|
|
61
|
-
// 如果是纯对象,则default可以为null
|
|
62
|
-
IfExtends<
|
|
63
|
-
D,
|
|
64
|
-
Exclude<R, undefined> | null,
|
|
65
|
-
unknown,
|
|
66
|
-
{ default: () => "⚠️类型错误⚠️" }
|
|
67
|
-
>,
|
|
68
|
-
// 如果不是纯对象,则default只能为getter返回值
|
|
69
|
-
IfExtends<
|
|
70
|
-
D,
|
|
71
|
-
Exclude<R, undefined>,
|
|
72
|
-
unknown,
|
|
73
|
-
{ default: () => "⚠️类型错误⚠️" }
|
|
74
|
-
>
|
|
75
|
-
>,
|
|
76
|
-
// 不包含undefined时,报错getter
|
|
77
|
-
{ getter: () => "⚠️类型不包含undefined⚠️ " }
|
|
78
|
-
>
|
|
79
|
-
// 非对象形式
|
|
80
|
-
: IfContains<
|
|
81
|
-
ReturnType<As<TStore[k], Func>>,
|
|
82
|
-
undefined,
|
|
83
|
-
() => "⚠️类型包含undefined,应写成对象形式⚠️",
|
|
84
|
-
unknown
|
|
85
|
-
>;
|
|
46
|
+
[k in keyof TStore]: IfContains<
|
|
47
|
+
ReturnType<As<TStore[k], Func>>,
|
|
48
|
+
undefined,
|
|
49
|
+
() => "⚠️返回类型中不可以包含undefined⚠️",
|
|
50
|
+
unknown
|
|
51
|
+
>;
|
|
86
52
|
},
|
|
87
53
|
> = Record<keyof TStore, unknown> extends Result ? unknown : Result;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { observable } from "mobx";
|
|
2
|
-
import type { DetailedType } from "../../../../types/DetailedType";
|
|
3
2
|
import { RootComponent } from "../..";
|
|
4
3
|
const user = observable({
|
|
5
4
|
name: "zhao",
|
|
@@ -29,44 +28,10 @@ RootComponent()({
|
|
|
29
28
|
userAge: () => user.age,
|
|
30
29
|
},
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
name: string;
|
|
34
|
-
age?: number;
|
|
35
|
-
};
|
|
36
|
-
type AllGoods = Record<string, User[] | undefined>;
|
|
37
|
-
const M_User = observable({
|
|
38
|
-
allUser: {
|
|
39
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
40
|
-
categoryB: [{ name: "zhao" }],
|
|
41
|
-
} as AllGoods,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// store中getter函数第一个参数为properties的类型
|
|
31
|
+
// 3. 返回类型错误
|
|
45
32
|
RootComponent()({
|
|
46
|
-
properties: {
|
|
47
|
-
categoryId: String as DetailedType<keyof typeof M_User.allUser>,
|
|
48
|
-
},
|
|
49
|
-
data: {
|
|
50
|
-
// categoryList:[],
|
|
51
|
-
},
|
|
52
33
|
store: {
|
|
53
|
-
// @ts-expect-error 1
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_categoryList: {
|
|
57
|
-
// @ts-expect-error 2 响应式数据不包含undefined时 不可以写成对象形式
|
|
58
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[],
|
|
59
|
-
default: [],
|
|
60
|
-
},
|
|
61
|
-
_categoryList1: {
|
|
62
|
-
getter: (data) => M_User.allUser[data.categoryId],
|
|
63
|
-
// @ts-expect-error 3 默认值应该为[]
|
|
64
|
-
default: 0,
|
|
65
|
-
},
|
|
66
|
-
_categoryList2: {
|
|
67
|
-
getter: (data) => M_User.allUser[data.categoryId]?.[0],
|
|
68
|
-
// @ts-expect-error 3 默认值应该为null
|
|
69
|
-
default: 0,
|
|
70
|
-
},
|
|
34
|
+
// @ts-expect-error 3.1 返回类型中不可以包含undefined
|
|
35
|
+
xxx: () => "xxx" as string | undefined,
|
|
71
36
|
},
|
|
72
37
|
});
|
|
@@ -22,49 +22,3 @@ interface StoreDocExpected {
|
|
|
22
22
|
|
|
23
23
|
// 返回类型为函数返回类型
|
|
24
24
|
void Checking<typeof storeDoc, StoreDocExpected, Test.Pass>;
|
|
25
|
-
|
|
26
|
-
type User = {
|
|
27
|
-
name: string;
|
|
28
|
-
age?: number;
|
|
29
|
-
};
|
|
30
|
-
type AllGoods = Record<string, User[]>;
|
|
31
|
-
const M_User = observable({
|
|
32
|
-
allUser: {
|
|
33
|
-
categoryA: [{ name: "zhao", age: 20 }],
|
|
34
|
-
categoryB: [{ name: "zhao" }],
|
|
35
|
-
} as AllGoods,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// store中getter函数第一个参数为properties的类型
|
|
39
|
-
RootComponent()({
|
|
40
|
-
properties: {
|
|
41
|
-
categoryId: String,
|
|
42
|
-
},
|
|
43
|
-
data: {
|
|
44
|
-
// categoryList:[],
|
|
45
|
-
},
|
|
46
|
-
store: {
|
|
47
|
-
// 1 响应式不包含undefined时 只能写成getter函数形式
|
|
48
|
-
categoryList: (data) => M_User.allUser[data.categoryId],
|
|
49
|
-
// 2 响应式数据包含undefined时 只能写成对象形式
|
|
50
|
-
_categoryList: {
|
|
51
|
-
getter: (data) => M_User.allUser[data.categoryId][0].age,
|
|
52
|
-
default: 0,
|
|
53
|
-
},
|
|
54
|
-
_categoryList1: {
|
|
55
|
-
getter: (data) => M_User.allUser[data.categoryId] as User[] | undefined,
|
|
56
|
-
// 默认值为[]
|
|
57
|
-
default: [],
|
|
58
|
-
},
|
|
59
|
-
_categoryList2: {
|
|
60
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
61
|
-
// 对象类型 默认值为User类型
|
|
62
|
-
default: { name: "zhao", age: 20 },
|
|
63
|
-
},
|
|
64
|
-
_categoryList3: {
|
|
65
|
-
getter: (data) => M_User.allUser[data.categoryId][0] as User | undefined,
|
|
66
|
-
// 对象类型 默认值可以为null
|
|
67
|
-
default: null,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CustomComponent, typeEqual } from "../../index";
|
|
2
|
+
import type { Wm } from "../index";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
const swiper = CustomComponent<{}, Wm.Swiper>()({
|
|
6
|
+
data: {
|
|
7
|
+
swiper_style: "16/9",
|
|
8
|
+
},
|
|
9
|
+
computed: {
|
|
10
|
+
swiper_class() {
|
|
11
|
+
return `w-full h-auto ${this.data.swiper_style}`;
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
events: {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
swiper_change(e) {
|
|
17
|
+
typeEqual<typeof e.detail.current, number>();
|
|
18
|
+
},
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
swiper_animationfinish(e) {
|
|
21
|
+
typeEqual<typeof e.detail.current, number>();
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -94,7 +94,7 @@ export type Swiper = CreateComponentType<"swiper", {
|
|
|
94
94
|
*/
|
|
95
95
|
easingFunction?: "defaultValue" | "linear" | "easeInCubic" | "easeOutCubic" | "easeInOutCubic";
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
events: {
|
|
98
98
|
/**
|
|
99
99
|
* current 改变时会触发 change 事件,event.detail = `{current, source}`
|
|
100
100
|
*/
|
|
@@ -11,7 +11,7 @@ import type { AddPrefix } from "./AddPrefix";
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* type $CustomA = CreateComponentType<"customA", {
|
|
13
13
|
* properties: { num: string };
|
|
14
|
-
*
|
|
14
|
+
* events: { onTap: string }
|
|
15
15
|
* }>;
|
|
16
16
|
*
|
|
17
17
|
* // 等同下面的类型
|
|
@@ -19,7 +19,7 @@ import type { AddPrefix } from "./AddPrefix";
|
|
|
19
19
|
* properties: {
|
|
20
20
|
* customA_num: string;
|
|
21
21
|
* };
|
|
22
|
-
*
|
|
22
|
+
* events: {
|
|
23
23
|
* customA_onTap: string;
|
|
24
24
|
* };
|
|
25
25
|
* ```
|
|
@@ -27,10 +27,10 @@ type Validator<
|
|
|
27
27
|
* ```ts
|
|
28
28
|
* type $CustomA = ExtendComponentType<
|
|
29
29
|
* { properties: { aaa_num: number };
|
|
30
|
-
*
|
|
30
|
+
* events: { aaa_xxx: string }
|
|
31
31
|
* },
|
|
32
32
|
* { properties: { aaa_str: string };
|
|
33
|
-
*
|
|
33
|
+
* events: { aaa_yyy: string }
|
|
34
34
|
* }>;
|
|
35
35
|
*
|
|
36
36
|
* // 等同下面的类型
|
|
@@ -39,7 +39,7 @@ type Validator<
|
|
|
39
39
|
* aaa_num: number;
|
|
40
40
|
* aaa_str: string;
|
|
41
41
|
* };
|
|
42
|
-
*
|
|
42
|
+
* events: {
|
|
43
43
|
* aaa_xxx: string;
|
|
44
44
|
* aaa_yyy: string;
|
|
45
45
|
* };
|
|
@@ -53,8 +53,8 @@ export type ExtendComponentType<
|
|
|
53
53
|
|
|
54
54
|
// type test0 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
55
55
|
|
|
56
|
-
// type test1 = ExtendComponentType<{
|
|
56
|
+
// type test1 = ExtendComponentType<{ events: { aaa_xxx: string } }, { events: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
57
57
|
|
|
58
58
|
// type test2 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
59
59
|
|
|
60
|
-
// type test3 = ExtendComponentType<{
|
|
60
|
+
// type test3 = ExtendComponentType<{ events: { aaa_xxx: string } }, { events: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
package/src/utils/nonNullable.ts
CHANGED
|
@@ -2,15 +2,18 @@ import type { IfContains } from "hry-types/src/Any/IfContains";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 使用此函数代替!断言
|
|
5
|
+
* 支持可选的第二个参数作为错误消息
|
|
5
6
|
* @param value 类型中必须包含 null 或 undefined
|
|
7
|
+
* @param message 可选,抛出错误时的消息
|
|
6
8
|
* @returns 去除 null 和 undefined 后的类型
|
|
7
9
|
*/
|
|
8
10
|
export function nonNullable<T>(
|
|
9
11
|
value: IfContains<T, null | undefined, T, "参数类型必须包含 null 或 undefined">,
|
|
12
|
+
message?: string,
|
|
10
13
|
): NonNullable<T> {
|
|
11
14
|
/* istanbul ignore next */
|
|
12
15
|
if (value === null || value === undefined) {
|
|
13
|
-
throw new Error(`${value} should not be null or undefined`);
|
|
16
|
+
throw new Error(message ?? `${value} should not be null or undefined`);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
return value as NonNullable<T>;
|