mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
add tests for generic type argument under strict null checks
This commit is contained in:
@@ -4,9 +4,10 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(14,7): error
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(15,7): error TS2345: Argument of type 'string' is not assignable to parameter of type 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(21,8): error TS2344: Type 'number' does not satisfy the constraint 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(22,8): error TS2344: Type 'string' does not satisfy the constraint 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(26,14): error TS2344: Type 'number' does not satisfy the constraint 'object'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts (6 errors) ====
|
||||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts (7 errors) ====
|
||||
function generic<T>(t: T) {}
|
||||
var a = {};
|
||||
var b = "42";
|
||||
@@ -41,4 +42,19 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveInGeneric.ts(22,8): error
|
||||
bound2<string>(); // expect error
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'string' does not satisfy the constraint 'object'.
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
|
||||
var y: Proxy<null>; // ok
|
||||
var z: Proxy<undefined> ; // ok
|
||||
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
@@ -21,6 +21,19 @@ bound2<{}>();
|
||||
bound2<Object>();
|
||||
bound2<number>(); // expect error
|
||||
bound2<string>(); // expect error
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // ok
|
||||
var z: Proxy<undefined> ; // ok
|
||||
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
|
||||
//// [nonPrimitiveInGeneric.js]
|
||||
@@ -41,3 +54,7 @@ bound2();
|
||||
bound2();
|
||||
bound2(); // expect error
|
||||
bound2(); // expect error
|
||||
var x; // error
|
||||
var y; // ok
|
||||
var z; // ok
|
||||
var u; // ok
|
||||
|
||||
@@ -21,9 +21,12 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(41,5): erro
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(45,5): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(45,7): error TS2339: Property 'toString' does not exist on type 'never'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(47,5): error TS2531: Object is possibly 'null'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(52,14): error TS2344: Type 'number' does not satisfy the constraint 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(53,14): error TS2344: Type 'null' does not satisfy the constraint 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(54,14): error TS2344: Type 'undefined' does not satisfy the constraint 'object'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts (19 errors) ====
|
||||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts (22 errors) ====
|
||||
|
||||
var a: object
|
||||
declare var b: object | null
|
||||
@@ -114,4 +117,22 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveStrictNull.ts(47,5): erro
|
||||
~
|
||||
!!! error TS2531: Object is possibly 'null'.
|
||||
}
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'number' does not satisfy the constraint 'object'.
|
||||
var y: Proxy<null>; // error
|
||||
~~~~
|
||||
!!! error TS2344: Type 'null' does not satisfy the constraint 'object'.
|
||||
var z: Proxy<undefined>; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS2344: Type 'undefined' does not satisfy the constraint 'object'.
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
@@ -47,6 +47,18 @@ if (typeof d === 'undefined') {
|
||||
} else {
|
||||
d.toString(); // error, object | null
|
||||
}
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // error
|
||||
var z: Proxy<undefined>; // error
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
|
||||
//// [nonPrimitiveStrictNull.js]
|
||||
@@ -91,3 +103,7 @@ if (typeof d === 'undefined') {
|
||||
else {
|
||||
d.toString(); // error, object | null
|
||||
}
|
||||
var x; // error
|
||||
var y; // error
|
||||
var z; // error
|
||||
var u; // ok
|
||||
|
||||
@@ -20,3 +20,16 @@ bound2<{}>();
|
||||
bound2<Object>();
|
||||
bound2<number>(); // expect error
|
||||
bound2<string>(); // expect error
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // ok
|
||||
var z: Proxy<undefined> ; // ok
|
||||
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
@@ -47,3 +47,15 @@ if (typeof d === 'undefined') {
|
||||
} else {
|
||||
d.toString(); // error, object | null
|
||||
}
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // error
|
||||
var z: Proxy<undefined>; // error
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
|
||||
Reference in New Issue
Block a user