MCPcopy
hub / github.com/ts-essentials/ts-essentials / testObjects

Function testObjects

lib/is-exact/index.test.ts:48–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48function testObjects() {
49 type ABC = { a: number; b: number; c: number };
50 type BC = { b: number; c: number };
51 type BC2 = { b: number; c: string };
52 type C = { c: number };
53
54 let abc: ABC = { a: 1, b: 2, c: 3 };
55 let abc2 = { a: 1, b: 2, c: 3 } as const;
56 let bc: BC = { b: 2, c: 3 };
57 let bc2: BC2 = { b: 2, c: "3" };
58 let bc3 = { b: 2, c: 3 } as const;
59 let bc4 = { b: 2, c: "3" } as const;
60 let c: C = { c: 3 };
61 let c2 = { c: 3 } as const;
62
63 const isBC = isExact<BC>();
64
65 // @ts-expect-error has different structure from BC (excessive property a)
66 isBC(abc);
67 // @ts-expect-error has different structure from BC (excessive property a)
68 isBC(abc2);
69
70 // has the same structure as BC
71 isBC(bc);
72 // @ts-expect-error has different structure from BC (c has different type)
73 isBC(bc2);
74 // @ts-expect-error: has different structure from BC (b and c have different types)
75 isBC(bc3);
76 // @ts-expect-error has different structure from BC (c has different type)
77 isBC(bc4);
78
79 // @ts-expect-error has different structure from BC (missing property b)
80 isBC(c);
81 // @ts-expect-error has different structure from BC (missing property b)
82 isBC(c2);
83}
84
85function testObjectUnionType() {
86 type ABC = { a: number; b: number; c: number };

Callers

nothing calls this directly

Calls 1

isExactFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…