1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
tests/cases/compiler/typeMatch2.ts(3,2): error TS2739: Type '{}' is missing the following properties from type '{ x: number; y: number; }': x, y
tests/cases/compiler/typeMatch2.ts(4,5): error TS2741: Property 'y' is missing in type '{ x: number; }' but required in type '{ x: number; y: number; }'.
tests/cases/compiler/typeMatch2.ts(5,20): error TS2322: Type '{ x: number; y: number; z: number; }' is not assignable to type '{ x: number; y: number; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
tests/cases/compiler/typeMatch2.ts(6,17): error TS2322: Type '{ x: number; z: number; }' is not assignable to type '{ x: number; y: number; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
tests/cases/compiler/typeMatch2.ts(18,5): error TS2322: Type 'Animal[]' is not assignable to type 'Giraffe[]'.
Property 'g' is missing in type 'Animal' but required in type 'Giraffe'.
tests/cases/compiler/typeMatch2.ts(22,5): error TS2322: 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[]'.
tests/cases/compiler/typeMatch2.ts(34,26): error TS2322: Type '{ x: number; y: any; z: number; }' is not assignable to type '{ x: number; y: number; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
tests/cases/compiler/typeMatch2.ts(35,5): error TS2741: Property 'y' is missing in type '{ x: number; }' but required in type '{ x: number; y: number; }'.
==== tests/cases/compiler/typeMatch2.ts (8 errors) ====
function f1() {
var a = { x: 1, y: 2 };
a = {}; // error
~
!!! error TS2739: Type '{}' is missing the following properties from type '{ x: number; y: number; }': x, y
a = { x: 1 }; // error
~
!!! error TS2741: Property 'y' is missing in type '{ x: number; }' but required in type '{ x: number; y: number; }'.
!!! related TS2728 tests/cases/compiler/typeMatch2.ts:2:18: 'y' is declared here.
a = { x: 1, y: 2, z: 3 };
~~~~
!!! error TS2322: Type '{ x: number; y: number; z: number; }' is not assignable to type '{ x: number; y: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
a = { x: 1, z: 3 }; // error
~~~~
!!! error TS2322: Type '{ x: number; z: number; }' is not assignable to type '{ x: number; y: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: 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
~~
!!! error TS2322: Type 'Animal[]' is not assignable to type 'Giraffe[]'.
!!! error TS2322: Property 'g' is missing in type 'Animal' but required in type 'Giraffe'.
!!! related TS2728 tests/cases/compiler/typeMatch2.ts:10:40: 'g' is declared here.
var xa = { f1: 5, f2: aa };
var xb = { f1: 5, f2: gg };
xa = xb; // Should be ok
xb = xa; // Not ok
~~
!!! error TS2322: Type '{ f1: number; f2: Animal[]; }' is not assignable to type '{ f1: number; f2: Giraffe[]; }'.
!!! error TS2322: Types of property 'f2' are incompatible.
!!! error TS2322: 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 };
~~~
!!! error TS2322: Type '{ x: number; y: any; z: number; }' is not assignable to type '{ x: number; y: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
a = { x: 1 }; // error
~
!!! error TS2741: Property 'y' is missing in type '{ x: number; }' but required in type '{ x: number; y: number; }'.
!!! related TS2728 tests/cases/compiler/typeMatch2.ts:30:21: 'y' is declared here.
var mf = function m(n) { return false; };
var zf = function z(n: number) { return true; };
mf=zf;
mf(_any);
zf(_any);
}
|