TypeScript/tests/baselines/reference/typeMatch2.errors.txt
2014-07-12 17:30:19 -07:00

66 lines
2.2 KiB
Plaintext

==== tests/cases/compiler/typeMatch2.ts (6 errors) ====
function f1() {
var a = { x: 1, y: 2 };
a = {}; // error
~
!!! Type '{}' is not assignable to type '{ x: number; y: number; }':
!!! Property 'x' is missing in type '{}'.
a = { x: 1 }; // error
~
!!! Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }':
!!! Property 'y' is missing in type '{ x: number; }'.
a = { x: 1, y: 2, z: 3 };
a = { x: 1, z: 3 }; // error
~
!!! Type '{ x: number; z: number; }' is not assignable to type '{ x: number; y: number; }':
!!! Property 'y' is missing in type '{ x: number; z: number; }'.
}
class Animal { private a; }
class Giraffe extends Animal { private g; }
function f2() {
var a = new Animal();
var g = new Giraffe();
var aa = [ a, a, a ];
var gg = [ g, g, g ];
aa = gg;
gg = aa; // error
~~
!!! Type 'Animal[]' is not assignable to type 'Giraffe[]':
!!! Type 'Animal' is not assignable to type 'Giraffe':
!!! Property 'g' is missing in type 'Animal'.
var xa = { f1: 5, f2: aa };
var xb = { f1: 5, f2: gg };
xa = xb; // Should be ok
xb = xa; // Not ok
~~
!!! Type '{ f1: number; f2: Animal[]; }' is not assignable to type '{ f1: number; f2: Giraffe[]; }':
!!! Types of property 'f2' are incompatible:
!!! Type 'Animal[]' is not assignable to type 'Giraffe[]':
!!! Type 'Animal' is not assignable to type 'Giraffe'.
}
function f4() {
var _any: any = 0;
var i = 5;
i = null;
i = undefined;
var a = { x: 1, y: 1 };
a = { x: 1, y: null };
a = { x: 1, y: undefined };
a = { x: 1, y: _any };
a = { x: 1, y: _any, z:1 };
a = { x: 1 }; // error
~
!!! Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }':
!!! Property 'y' is missing in type '{ x: number; }'.
var mf = function m(n) { return false; };
var zf = function z(n: number) { return true; };
mf=zf;
mf(_any);
zf(_any);
}