Skip to content

Commit d4e363a

Browse files
Accepted baselines.
1 parent c95d6f7 commit d4e363a

8 files changed

+1390
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
tests/cases/compiler/contextualNarrowingFromUnknownToObjects.ts(25,32): error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
2+
tests/cases/compiler/contextualNarrowingFromUnknownToObjects.ts(25,65): error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
3+
tests/cases/compiler/contextualNarrowingFromUnknownToObjects.ts(54,32): error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
4+
Type 'unknown' is not assignable to type 'object'.
5+
tests/cases/compiler/contextualNarrowingFromUnknownToObjects.ts(54,65): error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
6+
7+
8+
==== tests/cases/compiler/contextualNarrowingFromUnknownToObjects.ts (4 errors) ====
9+
declare function keysOfEmptyObject(o: {}): string[];
10+
declare function keysOfNonPrimitive(o: object): string[];
11+
12+
namespace implicitConstraints {
13+
export function keyLengthsEqualUsingEmptyObjectFn<T>(a: T, b: T): [T, T] | undefined {
14+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
15+
return undefined;
16+
}
17+
if (Array.isArray(a) || Array.isArray(b)) {
18+
return undefined;
19+
}
20+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
21+
return [a, b];
22+
}
23+
return undefined;
24+
}
25+
26+
export function keyLengthsEqualUsingNonPrimitiveFn<T>(a: T, b: T): [T, T] | undefined {
27+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
28+
return undefined;
29+
}
30+
if (Array.isArray(a) || Array.isArray(b)) {
31+
return undefined;
32+
}
33+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
34+
~
35+
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
36+
~
37+
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
38+
return [a, b];
39+
}
40+
return undefined;
41+
}
42+
}
43+
44+
// Explicit Constraints of 'unknown'
45+
namespace explicitConstraintsOfUnknown {
46+
export function keyLengthsEqualUsingEmptyObjectFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
47+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
48+
return undefined;
49+
}
50+
if (Array.isArray(a) || Array.isArray(b)) {
51+
return undefined;
52+
}
53+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
54+
return [a, b];
55+
}
56+
return undefined;
57+
}
58+
59+
export function keyLengthsEqualUsingNonPrimitiveFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
60+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
61+
return undefined;
62+
}
63+
if (Array.isArray(a) || Array.isArray(b)) {
64+
return undefined;
65+
}
66+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
67+
~
68+
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
69+
!!! error TS2345: Type 'unknown' is not assignable to type 'object'.
70+
~
71+
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'.
72+
return [a, b];
73+
}
74+
return undefined;
75+
}
76+
}
77+
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//// [contextualNarrowingFromUnknownToObjects.ts]
2+
declare function keysOfEmptyObject(o: {}): string[];
3+
declare function keysOfNonPrimitive(o: object): string[];
4+
5+
namespace implicitConstraints {
6+
export function keyLengthsEqualUsingEmptyObjectFn<T>(a: T, b: T): [T, T] | undefined {
7+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
8+
return undefined;
9+
}
10+
if (Array.isArray(a) || Array.isArray(b)) {
11+
return undefined;
12+
}
13+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
14+
return [a, b];
15+
}
16+
return undefined;
17+
}
18+
19+
export function keyLengthsEqualUsingNonPrimitiveFn<T>(a: T, b: T): [T, T] | undefined {
20+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
21+
return undefined;
22+
}
23+
if (Array.isArray(a) || Array.isArray(b)) {
24+
return undefined;
25+
}
26+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
27+
return [a, b];
28+
}
29+
return undefined;
30+
}
31+
}
32+
33+
// Explicit Constraints of 'unknown'
34+
namespace explicitConstraintsOfUnknown {
35+
export function keyLengthsEqualUsingEmptyObjectFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
36+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
37+
return undefined;
38+
}
39+
if (Array.isArray(a) || Array.isArray(b)) {
40+
return undefined;
41+
}
42+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
43+
return [a, b];
44+
}
45+
return undefined;
46+
}
47+
48+
export function keyLengthsEqualUsingNonPrimitiveFn<T extends unknown>(a: T, b: T): [T, T] | undefined {
49+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
50+
return undefined;
51+
}
52+
if (Array.isArray(a) || Array.isArray(b)) {
53+
return undefined;
54+
}
55+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
56+
return [a, b];
57+
}
58+
return undefined;
59+
}
60+
}
61+
62+
63+
//// [contextualNarrowingFromUnknownToObjects.js]
64+
var implicitConstraints;
65+
(function (implicitConstraints) {
66+
function keyLengthsEqualUsingEmptyObjectFn(a, b) {
67+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
68+
return undefined;
69+
}
70+
if (Array.isArray(a) || Array.isArray(b)) {
71+
return undefined;
72+
}
73+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
74+
return [a, b];
75+
}
76+
return undefined;
77+
}
78+
implicitConstraints.keyLengthsEqualUsingEmptyObjectFn = keyLengthsEqualUsingEmptyObjectFn;
79+
function keyLengthsEqualUsingNonPrimitiveFn(a, b) {
80+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
81+
return undefined;
82+
}
83+
if (Array.isArray(a) || Array.isArray(b)) {
84+
return undefined;
85+
}
86+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
87+
return [a, b];
88+
}
89+
return undefined;
90+
}
91+
implicitConstraints.keyLengthsEqualUsingNonPrimitiveFn = keyLengthsEqualUsingNonPrimitiveFn;
92+
})(implicitConstraints || (implicitConstraints = {}));
93+
// Explicit Constraints of 'unknown'
94+
var explicitConstraintsOfUnknown;
95+
(function (explicitConstraintsOfUnknown) {
96+
function keyLengthsEqualUsingEmptyObjectFn(a, b) {
97+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
98+
return undefined;
99+
}
100+
if (Array.isArray(a) || Array.isArray(b)) {
101+
return undefined;
102+
}
103+
if (keysOfEmptyObject(a).length !== keysOfEmptyObject(b).length) {
104+
return [a, b];
105+
}
106+
return undefined;
107+
}
108+
explicitConstraintsOfUnknown.keyLengthsEqualUsingEmptyObjectFn = keyLengthsEqualUsingEmptyObjectFn;
109+
function keyLengthsEqualUsingNonPrimitiveFn(a, b) {
110+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
111+
return undefined;
112+
}
113+
if (Array.isArray(a) || Array.isArray(b)) {
114+
return undefined;
115+
}
116+
if (keysOfNonPrimitive(a).length !== keysOfNonPrimitive(b).length) {
117+
return [a, b];
118+
}
119+
return undefined;
120+
}
121+
explicitConstraintsOfUnknown.keyLengthsEqualUsingNonPrimitiveFn = keyLengthsEqualUsingNonPrimitiveFn;
122+
})(explicitConstraintsOfUnknown || (explicitConstraintsOfUnknown = {}));

0 commit comments

Comments
 (0)