Skip to content

Commit 186ce38

Browse files
add tests for generic type argument under strict null checks
1 parent c19221c commit 186ce38

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

tests/baselines/reference/nonPrimitiveInGeneric.errors.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(14,7): error
44
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(15,7): error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
55
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(21,8): error TS2344: Type 'number' does not satisfy the constraint 'object'.
66
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(22,8): error TS2344: Type 'string' does not satisfy the constraint 'object'.
7+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(26,14): error TS2344: Type 'number' does not satisfy the constraint 'object'.
78

89

9-
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts (6 errors) ====
10+
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts (7 errors) ====
1011
function generic<T>(t: T) {}
1112
var a = {};
1213
var b = "42";
@@ -41,4 +42,19 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(22,8): error
4142
bound2<string>(); // expect error
4243
~~~~~~
4344
!!! error TS2344: Type 'string' does not satisfy the constraint 'object'.
45+
46+
interface Proxy<T extends object> {}
47+
48+
var x: Proxy<number>; // error
49+
~~~~~~
50+
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
51+
var y: Proxy<null>; // ok
52+
var z: Proxy<undefined> ; // ok
53+
54+
55+
interface Blah {
56+
foo: number;
57+
}
58+
59+
var u: Proxy<Blah>; // ok
4460

tests/baselines/reference/nonPrimitiveInGeneric.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ bound2<{}>();
2121
bound2<Object>();
2222
bound2<number>(); // expect error
2323
bound2<string>(); // expect error
24+
25+
interface Proxy<T extends object> {}
26+
27+
var x: Proxy<number>; // error
28+
var y: Proxy<null>; // ok
29+
var z: Proxy<undefined> ; // ok
30+
31+
32+
interface Blah {
33+
foo: number;
34+
}
35+
36+
var u: Proxy<Blah>; // ok
2437

2538

2639
//// [nonPrimitiveInGeneric.js]
@@ -41,3 +54,7 @@ bound2();
4154
bound2();
4255
bound2(); // expect error
4356
bound2(); // expect error
57+
var x; // error
58+
var y; // ok
59+
var z; // ok
60+
var u; // ok

tests/baselines/reference/nonPrimitiveStrictNull.errors.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(41,5): erro
2121
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(45,5): error TS2532: Object is possibly 'undefined'.
2222
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(45,7): error TS2339: Property 'toString' does not exist on type 'never'.
2323
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(47,5): error TS2531: Object is possibly 'null'.
24+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(52,14): error TS2344: Type 'number' does not satisfy the constraint 'object'.
25+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(53,14): error TS2344: Type 'null' does not satisfy the constraint 'object'.
26+
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(54,14): error TS2344: Type 'undefined' does not satisfy the constraint 'object'.
2427

2528

26-
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts (19 errors) ====
29+
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts (22 errors) ====
2730

2831
var a: object
2932
declare var b: object | null
@@ -114,4 +117,22 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(47,5): erro
114117
~
115118
!!! error TS2531: Object is possibly 'null'.
116119
}
120+
121+
interface Proxy<T extends object> {}
122+
123+
var x: Proxy<number>; // error
124+
~~~~~~
125+
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
126+
var y: Proxy<null>; // error
127+
~~~~
128+
!!! error TS2344: Type 'null' does not satisfy the constraint 'object'.
129+
var z: Proxy<undefined>; // error
130+
~~~~~~~~~
131+
!!! error TS2344: Type 'undefined' does not satisfy the constraint 'object'.
132+
133+
interface Blah {
134+
foo: number;
135+
}
136+
137+
var u: Proxy<Blah>; // ok
117138

tests/baselines/reference/nonPrimitiveStrictNull.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ if (typeof d === 'undefined') {
4747
} else {
4848
d.toString(); // error, object | null
4949
}
50+
51+
interface Proxy<T extends object> {}
52+
53+
var x: Proxy<number>; // error
54+
var y: Proxy<null>; // error
55+
var z: Proxy<undefined>; // error
56+
57+
interface Blah {
58+
foo: number;
59+
}
60+
61+
var u: Proxy<Blah>; // ok
5062

5163

5264
//// [nonPrimitiveStrictNull.js]
@@ -91,3 +103,7 @@ if (typeof d === 'undefined') {
91103
else {
92104
d.toString(); // error, object | null
93105
}
106+
var x; // error
107+
var y; // error
108+
var z; // error
109+
var u; // ok

tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ bound2<{}>();
2020
bound2<Object>();
2121
bound2<number>(); // expect error
2222
bound2<string>(); // expect error
23+
24+
interface Proxy<T extends object> {}
25+
26+
var x: Proxy<number>; // error
27+
var y: Proxy<null>; // ok
28+
var z: Proxy<undefined> ; // ok
29+
30+
31+
interface Blah {
32+
foo: number;
33+
}
34+
35+
var u: Proxy<Blah>; // ok

tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ if (typeof d === 'undefined') {
4747
} else {
4848
d.toString(); // error, object | null
4949
}
50+
51+
interface Proxy<T extends object> {}
52+
53+
var x: Proxy<number>; // error
54+
var y: Proxy<null>; // error
55+
var z: Proxy<undefined>; // error
56+
57+
interface Blah {
58+
foo: number;
59+
}
60+
61+
var u: Proxy<Blah>; // ok

0 commit comments

Comments
 (0)