diff --git a/scripts/clean/entity/unwrap.ts b/scripts/clean/entity/unwrap.ts index c135409f..4866c2cf 100644 --- a/scripts/clean/entity/unwrap.ts +++ b/scripts/clean/entity/unwrap.ts @@ -1,4 +1,4 @@ -import { type Unwrap, type WrappedValue, type IsEqual, type Transformer, type TransformerFunction, type SimplifyTopLevel, type DeepReadonly, type GetKindValue, type Kind, unwrap, isWrappedValue } from "@scripts/common"; +import { type Unwrap, type WrappedValue, type IsEqual, type Transformer, type TransformerFunction, type SimplifyTopLevel, type DeepReadonly, type GetKindValue, type Kind, unwrap, isWrappedValue, isRuntimeKind } from "@scripts/common"; import { entityKind, type Entity } from "."; import { flagKind } from "../flag"; @@ -54,7 +54,7 @@ export type UnwrapEntity< GetKindValue > } - : {} + : { _flags?: Record } ) > >; @@ -124,7 +124,7 @@ export function unwrapEntity< unwrapEntity._entityName = entity[prop]; } else if (prop === flagKind.runTimeKey) { unwrapEntity._flags = entity[prop]; - } else { + } else if (!isRuntimeKind(prop)) { unwrapEntity[prop] = unwrapEntityProperty(entity[prop], params); } } diff --git a/tests/clean/entity/unwrap.test.ts b/tests/clean/entity/unwrap.test.ts index 98b4d578..72cd2d7c 100644 --- a/tests/clean/entity/unwrap.test.ts +++ b/tests/clean/entity/unwrap.test.ts @@ -1,4 +1,5 @@ import { DClean, DDataParser, pipe, type ExpectType } from "@scripts"; +import { newTypeKind } from "@scripts/clean"; describe("unwrapEntityProperty", () => { it("unwraps wrapped values without transformer and supports pipe", () => { @@ -172,7 +173,7 @@ describe("unwrapEntity", () => { const result = pipe( featuredEntity, - (value) => DClean.unwrapEntity(value), + DClean.unwrapEntity, ); expect(result).toStrictEqual({ @@ -233,6 +234,8 @@ describe("unwrapEntity", () => { }, }); + newTypeKind.setTo(entity, ""); + const result = DClean.unwrapEntity( entity, { @@ -248,5 +251,21 @@ describe("unwrapEntity", () => { }, _entityName: "User", }); + + type check = ExpectType< + typeof result, + { + readonly name: "alice"; + readonly role: "member"; + readonly profile: { + readonly label: "member"; + }; + readonly _entityName: "User"; + readonly _flags?: { + readonly [x: string]: unknown; + }; + }, + "strict" + >; }); });