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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
tests/cases/compiler/incompatibleTypes.ts(6,12): error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type 'IFoo1'.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/incompatibleTypes.ts(16,12): error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type 'IFoo2'.
Type '(n: number) => number' is not assignable to type '(s: string) => number'.
Types of parameters 'n' and 's' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/incompatibleTypes.ts(26,12): error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'IFoo3'.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/incompatibleTypes.ts(34,12): error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type 'IFoo4'.
Type '{ c: { b: string; }; d: string; }' is missing the following properties from type '{ a: { a: string; }; b: string; }': a, b
tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
Types of property 'p1' are incompatible.
Type '() => string' is not assignable to type '(s: string) => number'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/incompatibleTypes.ts(49,7): error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'.
Object literal may only specify known properties, and 'e' does not exist in type '{ c: { b: string; }; d: string; }'.
tests/cases/compiler/incompatibleTypes.ts(66,47): error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
Object literal may only specify known properties, and 'e' does not exist in type '{ a: { a: string; }; b: string; }'.
tests/cases/compiler/incompatibleTypes.ts(72,5): error TS2322: Type '5' is not assignable to type '() => string'.
tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) => number' is not assignable to type '() => any'.
==== tests/cases/compiler/incompatibleTypes.ts (9 errors) ====
interface IFoo1 {
p1(): number;
}
class C1 implements IFoo1 { // incompatible on the return type
public p1() {
~~
!!! error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type 'IFoo1'.
!!! error TS2416: Type '() => string' is not assignable to type '() => number'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
return "s";
}
}
interface IFoo2 {
p1(s:string): number;
}
class C2 implements IFoo2 { // incompatible on the param type
public p1(n:number) {
~~
!!! error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type 'IFoo2'.
!!! error TS2416: Type '(n: number) => number' is not assignable to type '(s: string) => number'.
!!! error TS2416: Types of parameters 'n' and 's' are incompatible.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
return 0;
}
}
interface IFoo3 {
p1: string;
}
class C3 implements IFoo3 { // incompatible on the property type
public p1: number;
~~
!!! error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'IFoo3'.
!!! error TS2416: Type 'number' is not assignable to type 'string'.
}
interface IFoo4 {
p1: { a: { a: string; }; b: string; };
}
class C4 implements IFoo4 { // incompatible on the property type
public p1: { c: { b: string; }; d: string; };
~~
!!! error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type 'IFoo4'.
!!! error TS2416: Type '{ c: { b: string; }; d: string; }' is missing the following properties from type '{ a: { a: string; }; b: string; }': a, b
}
function if1(i: IFoo1): void;
function if1(i: IFoo2): void;
function if1(a: any) { }
var c1: C1;
var c2: C2;
if1(c1);
~~
!!! error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
!!! error TS2345: Types of property 'p1' are incompatible.
!!! error TS2345: Type '() => string' is not assignable to type '(s: string) => number'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
function of1(n: { a: { a: string; }; b: string; }): number;
function of1(s: { c: { b: string; }; d: string; }): string;
function of1(a: any) { return null; }
of1({ e: 0, f: 0 });
~~~~
!!! error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'.
!!! error TS2345: Object literal may only specify known properties, and 'e' does not exist in type '{ c: { b: string; }; d: string; }'.
interface IMap {
[key:string]:string;
}
function foo(fn:() => void) {
}
function bar() {
var map:IMap;
foo(() => {
map = {};
});
}
var o1: { a: { a: string; }; b: string; } = { e: 0, f: 0 };
~~~~
!!! error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'e' does not exist in type '{ a: { a: string; }; b: string; }'.
var a1 = [{ e: 0, f: 0 }, { e: 0, f: 0 }, { e: 0, g: 0 }];
var i1c1: { (): string; } = 5;
~~~~
!!! error TS2322: Type '5' is not assignable to type '() => string'.
var fp1: () =>any = a => 0;
~~~
!!! error TS2322: Type '(a: any) => number' is not assignable to type '() => any'.
|