Skip to content

Commit

Permalink
fix: 修复RootCOmonent在properties的可选数组类型时,value验证错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
missannil committed Jan 3, 2024
1 parent 837a0c3 commit b836e83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions jest/onlySubComonent/onlySubComonent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ describe("RootComponent-events", () => {
test("events字段 onTap事件", () => {
expect(comp.instance.data.aaa_num).toBe(comp.instance.data.aaa2_num);
});

// 有些测试描述不对,下次再改
});
3 changes: 2 additions & 1 deletion src/api/RootComponent/Properties/PropertiesValueValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
import type { NonReadonly } from "hry-types/src/Object/NonReadonly";
import type { InferDetailedType } from "../../../types/InferDetailedType";

/**
Expand All @@ -12,7 +13,7 @@ export type PropertiesValueValidator<
k in keyof TProperties as TProperties[k] extends {
type: infer R;
value: infer V;
} ? V extends InferDetailedType<R> ? never
} ? NonReadonly<V> extends NonReadonly<InferDetailedType<R>> ? never
: k
: never
]: { value: () => "⚠️类型错误⚠️" };
Expand Down
8 changes: 7 additions & 1 deletion src/api/RootComponent/Properties/test/normalOptional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const OptionalDoc = RootComponent()({
},
optional_tuple: {
type: Array as unknown as DetailedType<[number, string, boolean]>, // 元组类型
value: [1, "a", true] as [number, string, boolean],
value: [1, "a", true],
},
optional_obj: {
type: Object as DetailedType<Mock_User>, // 对象类型
Expand All @@ -38,6 +38,10 @@ const OptionalDoc = RootComponent()({
value: "string",
optionalTypes: [Number],
},
optional_arr: {
type: Array as DetailedType<string[]>,
value: [],
},
},
methods: {
foo() {
Expand All @@ -52,6 +56,7 @@ const OptionalDoc = RootComponent()({
optional_obj: Mock_User | null;
optional_objOrNull: Mock_User | null;
optional_union: string | number;
optional_arr: string[];
} & IInjectData
>,
Test.Pass
Expand All @@ -69,6 +74,7 @@ type OptionalDocExpected = {
optional_obj?: Mock_User | null;
optional_objOrNull?: Mock_User | null;
optional_union?: string | number;
optional_arr?: string[];
};
methods: {
foo(): void;
Expand Down

0 comments on commit b836e83

Please sign in to comment.