57 lines
No EOL
3.1 KiB
Text
57 lines
No EOL
3.1 KiB
Text
tests/cases/compiler/widenedTypes.ts(2,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
|
|
tests/cases/compiler/widenedTypes.ts(5,1): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
|
|
tests/cases/compiler/widenedTypes.ts(6,7): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter
|
|
tests/cases/compiler/widenedTypes.ts(8,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
|
|
tests/cases/compiler/widenedTypes.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/widenedTypes.ts(18,1): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/widenedTypes.ts(23,5): error TS2322: Type 'number[]' is not assignable to type 'string[]'.
|
|
Type 'number' is not assignable to type 'string'.
|
|
tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'.
|
|
Index signatures are incompatible.
|
|
Type 'number' is not assignable to type 'string'.
|
|
|
|
|
|
==== tests/cases/compiler/widenedTypes.ts (8 errors) ====
|
|
|
|
null instanceof (() => { });
|
|
~~~~
|
|
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
|
|
({}) instanceof null; // Ok because null is a subtype of function
|
|
|
|
null in {};
|
|
~~~~
|
|
!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
|
|
"" in null;
|
|
~~~~
|
|
!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter
|
|
|
|
for (var a in null) { }
|
|
~~~~
|
|
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
|
|
|
|
var t = [3, (3, null)];
|
|
t[3] = "";
|
|
~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
|
|
var x: typeof undefined = 3;
|
|
x = 3;
|
|
|
|
var y;
|
|
var u = [3, (y = null)];
|
|
u[3] = "";
|
|
~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
|
|
var ob: { x: typeof undefined } = { x: "" };
|
|
|
|
// Highlights the difference between array literals and object literals
|
|
var arr: string[] = [3, null]; // not assignable because null is not widened. BCT is {}
|
|
~~~
|
|
!!! error TS2322: Type 'number[]' is not assignable to type 'string[]'.
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
var obj: { [x: string]: string; } = { x: 3, y: null }; // assignable because null is widened, and therefore BCT is any
|
|
~~~
|
|
!!! error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'.
|
|
!!! error TS2322: Index signatures are incompatible.
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'. |