Skip to content

Commit c95d6f7

Browse files
Added test case.
1 parent 0885482 commit c95d6f7

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
// @strictNullChecks: true, false
3+
// @target: esnext
4+
5+
declare function keysOfEmptyObject(o: {}): string[];
6+
declare function keysOfNonPrimitive(o: object): string[];
7+
8+
namespace implicitConstraints {
9+
export function keyLengthsEqualUsingEmptyObjectFn<T>(a: T, b: T): [T, T] | undefined {
10+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
11+
return undefined;
12+
}
13+
if (Array.isArray(a) || Array.isArray(b)) {
14+
return undefined;
15+
}
16+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
17+
return [a, b];
18+
}
19+
return undefined;
20+
}
21+
22+
export function keyLengthsEqualUsingNonPrimitiveFn<T>(a: T, b: T): [T, T] | undefined {
23+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
24+
return undefined;
25+
}
26+
if (Array.isArray(a) || Array.isArray(b)) {
27+
return undefined;
28+
}
29+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
30+
return [a, b];
31+
}
32+
return undefined;
33+
}
34+
}
35+
36+
// Explicit Constraints of 'unknown'
37+
namespace explicitConstraintsOfUnknown {
38+
export function keyLengthsEqualUsingEmptyObjectFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
39+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
40+
return undefined;
41+
}
42+
if (Array.isArray(a) || Array.isArray(b)) {
43+
return undefined;
44+
}
45+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
46+
return [a, b];
47+
}
48+
return undefined;
49+
}
50+
51+
export function keyLengthsEqualUsingNonPrimitiveFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
52+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
53+
return undefined;
54+
}
55+
if (Array.isArray(a) || Array.isArray(b)) {
56+
return undefined;
57+
}
58+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
59+
return [a, b];
60+
}
61+
return undefined;
62+
}
63+
}

0 commit comments

Comments
 (0)