|
1 | 1 | import { expectTypeOf } from "expect-type";
|
2 | 2 |
|
3 |
| -import { Primitives } from "../src/Primitives"; |
| 3 | +import { Primitives } from "../src"; |
4 | 4 | import { Course } from "./Course";
|
5 | 5 | import { DeliveryInfo } from "./DeliveryInfo";
|
6 | 6 | import { Learner } from "./Learner";
|
| 7 | +import { Product } from "./Product"; |
7 | 8 | import { User } from "./User";
|
| 9 | +import { Video } from "./Video"; |
8 | 10 |
|
9 | 11 | describe("Primitives", () => {
|
10 | 12 | it("should ensure to only return primitive properties excluding methods", () => {
|
@@ -52,4 +54,27 @@ describe("Primitives", () => {
|
52 | 54 |
|
53 | 55 | expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
|
54 | 56 | });
|
| 57 | + |
| 58 | + it("should get primitive type in case it is not a value object", () => { |
| 59 | + type actualPrimitives = Primitives<Product>; |
| 60 | + |
| 61 | + type expectedPrimitives = { |
| 62 | + readonly active: boolean; |
| 63 | + readonly createdAt: Date; |
| 64 | + }; |
| 65 | + |
| 66 | + expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>(); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should infer the optional properties", () => { |
| 70 | + type actualPrimitives = Primitives<Video>; |
| 71 | + |
| 72 | + type expectedPrimitives = { |
| 73 | + readonly id: string; |
| 74 | + readonly name: string | undefined; |
| 75 | + readonly duration: number | undefined; |
| 76 | + }; |
| 77 | + |
| 78 | + expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>(); |
| 79 | + }); |
55 | 80 | });
|
0 commit comments