import { Checking, type Test } from "hry-types"; import type { ReadonlyDeep } from "hry-types/src/Any/_api"; import { RootComponent } from "../.."; import type { SpecificType } from "../../../.."; import { type Mock_Cart, mock_requiredTypes, mock_requiredUnion, type Mock_User, } from "../../Properties/expected/normalRequired"; import type { OptionalType } from "../../Properties/PropertiesConstraint"; const mock_optional = { optional_num: { type: Number, value: 123, }, optional_gender: { type: String as SpecificType<"male" | "female">, value: "male" as const, }, optional_obj: { type: Object as SpecificType, value: { id: "id", name: "name", age: 20, }, }, optional_objOrNull: { type: Object as SpecificType, // 可选类型定义null默认值方可为null value: null, }, } satisfies Record; /** * watch properties字段 深度只读, 必传对象字段newValue去除null */ RootComponent()({ properties: { ...mock_requiredTypes, ...mock_requiredUnion, ...mock_optional, }, watch: { // 必传单一字段 str(newValue, oldValue) { Checking; Checking; }, num(newValue, oldValue) { Checking; Checking; }, bool(newValue, oldValue) { Checking; Checking; }, arr(newValue, oldValue) { newValue; // readonly ReadonlyDeep[] oldValue; // readonly ReadonlyDeep[] // ts中很多不是错误的错误,写 typeof newValue 结果是错误 Checking; // ts中很多不是错误的错误,写 readonly ReadonlyDeep[] 结果是正确的 Checking[], Test.Pass>; }, obj(newValue, oldValue) { Checking; Checking; }, tuple(newValue, oldValue) { Checking; Checking; }, union_str(newValue, oldValue) { Checking<"male" | "female", typeof newValue, Test.Pass>; Checking<"male" | "female", typeof oldValue, Test.Pass>; }, union_num(newValue, oldValue) { Checking<0 | 1 | 2, typeof newValue, Test.Pass>; Checking<0 | 1 | 2, typeof oldValue, Test.Pass>; }, union_bool(newValue, oldValue) { Checking; Checking; }, union_arr(newValue, oldValue) { Checking; Checking; }, union_obj(newValue, oldValue) { Checking, typeof newValue, Test.Pass>; Checking, typeof oldValue, Test.Pass>; }, // 必传多类型联合 union_str_num_bool(newValue, oldValue) { Checking; Checking; }, union_literalStr_Literalnum(newValue, oldValue) { Checking<0 | 1 | 2 | "male" | "female", typeof newValue, Test.Pass>; Checking<0 | 1 | 2 | "male" | "female", typeof oldValue, Test.Pass>; }, union_mockUser_num(newValue, oldValue) { Checking, typeof newValue, Test.Pass>; Checking, typeof oldValue, Test.Pass>; }, // 可选字段 optional_gender(newValue, oldValue) { Checking<"male" | "female", typeof newValue, Test.Pass>; Checking<"male" | "female", typeof oldValue, Test.Pass>; }, optional_num(newValue, oldValue) { Checking; Checking; }, optional_obj(newValue, oldValue) { Checking, typeof newValue, Test.Pass>; Checking | null, typeof oldValue, Test.Pass>; }, // 对象的二段key "optional_obj.age"(newValue, oldValue) { Checking; Checking; }, "optional_obj.id"(newValue, oldValue) { Checking; Checking; }, "optional_objOrNull.age"() { }, }, });