Skip to content

Commit dc319e7

Browse files
committed
Expand test
1 parent e6decb5 commit dc319e7

4 files changed

+159
-4
lines changed

Diff for: tests/baselines/reference/unconstrainedTypeParameterNarrowing.js

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ function f2<T extends unknown>(x: T) {
1111
}
1212
}
1313

14+
// #48468 but with an explicit constraint so as to not trigger the `{}` and unconstrained type parameter bug
15+
function deepEquals<T extends unknown>(a: T, b: T) {
16+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
17+
return false;
18+
}
19+
if (Array.isArray(a) || Array.isArray(b)) {
20+
return false;
21+
}
22+
if (Object.keys(a).length !== Object.keys(b).length) {
23+
return false;
24+
}
25+
return true;
26+
}
27+
1428
function g(x: object) {}
1529

1630
//// [unconstrainedTypeParameterNarrowing.js]
@@ -25,4 +39,17 @@ function f2(x) {
2539
g(x);
2640
}
2741
}
42+
// #48468 but with an explicit constraint so as to not trigger the `{}` and unconstrained type parameter bug
43+
function deepEquals(a, b) {
44+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
45+
return false;
46+
}
47+
if (Array.isArray(a) || Array.isArray(b)) {
48+
return false;
49+
}
50+
if (Object.keys(a).length !== Object.keys(b).length) {
51+
return false;
52+
}
53+
return true;
54+
}
2855
function g(x) { }

Diff for: tests/baselines/reference/unconstrainedTypeParameterNarrowing.symbols

+52-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function f1<T>(x: T) {
1010
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 0, 15))
1111

1212
g(x);
13-
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 10, 1))
13+
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 24, 1))
1414
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 0, 15))
1515
}
1616
}
@@ -26,12 +26,60 @@ function f2<T extends unknown>(x: T) {
2626
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 6, 31))
2727

2828
g(x);
29-
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 10, 1))
29+
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 24, 1))
3030
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 6, 31))
3131
}
3232
}
3333

34+
// #48468 but with an explicit constraint so as to not trigger the `{}` and unconstrained type parameter bug
35+
function deepEquals<T extends unknown>(a: T, b: T) {
36+
>deepEquals : Symbol(deepEquals, Decl(unconstrainedTypeParameterNarrowing.ts, 10, 1))
37+
>T : Symbol(T, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 20))
38+
>a : Symbol(a, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 39))
39+
>T : Symbol(T, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 20))
40+
>b : Symbol(b, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 44))
41+
>T : Symbol(T, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 20))
42+
43+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
44+
>a : Symbol(a, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 39))
45+
>b : Symbol(b, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 44))
46+
>a : Symbol(a, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 39))
47+
>b : Symbol(b, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 44))
48+
49+
return false;
50+
}
51+
if (Array.isArray(a) || Array.isArray(b)) {
52+
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
53+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
54+
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
55+
>a : Symbol(a, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 39))
56+
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
57+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
58+
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
59+
>b : Symbol(b, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 44))
60+
61+
return false;
62+
}
63+
if (Object.keys(a).length !== Object.keys(b).length) {
64+
>Object.keys(a).length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
65+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
66+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
67+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
68+
>a : Symbol(a, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 39))
69+
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
70+
>Object.keys(b).length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
71+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
72+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
73+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
74+
>b : Symbol(b, Decl(unconstrainedTypeParameterNarrowing.ts, 13, 44))
75+
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
76+
77+
return false;
78+
}
79+
return true;
80+
}
81+
3482
function g(x: object) {}
35-
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 10, 1))
36-
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 12, 11))
83+
>g : Symbol(g, Decl(unconstrainedTypeParameterNarrowing.ts, 24, 1))
84+
>x : Symbol(x, Decl(unconstrainedTypeParameterNarrowing.ts, 26, 11))
3785

Diff for: tests/baselines/reference/unconstrainedTypeParameterNarrowing.types

+66
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,72 @@ function f2<T extends unknown>(x: T) {
3737
}
3838
}
3939

40+
// #48468 but with an explicit constraint so as to not trigger the `{}` and unconstrained type parameter bug
41+
function deepEquals<T extends unknown>(a: T, b: T) {
42+
>deepEquals : <T extends unknown>(a: T, b: T) => boolean
43+
>a : T
44+
>b : T
45+
46+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
47+
>typeof a !== "object" || typeof b !== "object" || !a || !b : boolean
48+
>typeof a !== "object" || typeof b !== "object" || !a : boolean
49+
>typeof a !== "object" || typeof b !== "object" : boolean
50+
>typeof a !== "object" : boolean
51+
>typeof a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
52+
>a : T
53+
>"object" : "object"
54+
>typeof b !== "object" : boolean
55+
>typeof b : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
56+
>b : T
57+
>"object" : "object"
58+
>!a : boolean
59+
>a : T & (object | null)
60+
>!b : boolean
61+
>b : T & (object | null)
62+
63+
return false;
64+
>false : false
65+
}
66+
if (Array.isArray(a) || Array.isArray(b)) {
67+
>Array.isArray(a) || Array.isArray(b) : boolean
68+
>Array.isArray(a) : boolean
69+
>Array.isArray : (arg: any) => arg is any[]
70+
>Array : ArrayConstructor
71+
>isArray : (arg: any) => arg is any[]
72+
>a : T & object
73+
>Array.isArray(b) : boolean
74+
>Array.isArray : (arg: any) => arg is any[]
75+
>Array : ArrayConstructor
76+
>isArray : (arg: any) => arg is any[]
77+
>b : T & object
78+
79+
return false;
80+
>false : false
81+
}
82+
if (Object.keys(a).length !== Object.keys(b).length) {
83+
>Object.keys(a).length !== Object.keys(b).length : boolean
84+
>Object.keys(a).length : number
85+
>Object.keys(a) : string[]
86+
>Object.keys : (o: object) => string[]
87+
>Object : ObjectConstructor
88+
>keys : (o: object) => string[]
89+
>a : T & object
90+
>length : number
91+
>Object.keys(b).length : number
92+
>Object.keys(b) : string[]
93+
>Object.keys : (o: object) => string[]
94+
>Object : ObjectConstructor
95+
>keys : (o: object) => string[]
96+
>b : T & object
97+
>length : number
98+
99+
return false;
100+
>false : false
101+
}
102+
return true;
103+
>true : true
104+
}
105+
40106
function g(x: object) {}
41107
>g : (x: object) => void
42108
>x : object

Diff for: tests/cases/compiler/unconstrainedTypeParameterNarrowing.ts

+14
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,18 @@ function f2<T extends unknown>(x: T) {
1111
}
1212
}
1313

14+
// #48468 but with an explicit constraint so as to not trigger the `{}` and unconstrained type parameter bug
15+
function deepEquals<T extends unknown>(a: T, b: T) {
16+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) {
17+
return false;
18+
}
19+
if (Array.isArray(a) || Array.isArray(b)) {
20+
return false;
21+
}
22+
if (Object.keys(a).length !== Object.keys(b).length) {
23+
return false;
24+
}
25+
return true;
26+
}
27+
1428
function g(x: object) {}

0 commit comments

Comments
 (0)