diff --git a/package-lock.json b/package-lock.json index 2e18332..85ef967 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@codelytv/primitives-type", - "version": "1.0.6", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@codelytv/primitives-type", - "version": "1.0.6", + "version": "1.1.0", "license": "GPL-3.0", "devDependencies": { "@types/jest": "^27.5.2", diff --git a/package.json b/package.json index f65e143..8054dcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codelytv/primitives-type", - "version": "1.0.6", + "version": "1.1.0", "description": "Type entity primitives from value objects", "keywords": [ "typescript", diff --git a/src/Primitives.ts b/src/Primitives.ts index d620f2a..f8709b9 100644 --- a/src/Primitives.ts +++ b/src/Primitives.ts @@ -17,8 +17,10 @@ type ValueObjectValue = T extends PrimitiveTypes ? U[] : T extends Array ? Array> - : T extends { [K in keyof Properties]: infer U } + : T extends { [K in keyof Properties]: unknown } ? { [K in keyof Properties]: ValueObjectValue[K]> } + : T extends unknown + ? T : never; export type Primitives = { diff --git a/tests/Metadata.ts b/tests/Metadata.ts new file mode 100644 index 0000000..6eb0d0a --- /dev/null +++ b/tests/Metadata.ts @@ -0,0 +1,11 @@ +import { Primitives } from "../src"; + +export class Metadata { + constructor(public readonly data: Record) {} + + toPrimitives(): Primitives { + return { + data: this.data, + }; + } +} diff --git a/tests/Primitives.test.ts b/tests/Primitives.test.ts index a8fcdb4..3dfc926 100644 --- a/tests/Primitives.test.ts +++ b/tests/Primitives.test.ts @@ -4,6 +4,7 @@ import { Primitives } from "../src"; import { Course } from "./Course"; import { DeliveryInfo } from "./DeliveryInfo"; import { Learner } from "./Learner"; +import { Metadata } from "./Metadata"; import { Product } from "./Product"; import { User } from "./User"; import { Video } from "./Video"; @@ -79,4 +80,14 @@ describe("Primitives", () => { expectTypeOf().toEqualTypeOf(); }); + + it("should infer properties with unknown type", () => { + type actualPrimitives = Primitives; + + type expectedPrimitives = { + readonly data: Record; + }; + + expectTypeOf().toEqualTypeOf(); + }); });