71 lines
No EOL
3.2 KiB
Text
71 lines
No EOL
3.2 KiB
Text
tests/cases/compiler/genericSpecializations3.ts(8,7): error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo<number>'.
|
|
Types of property 'foo' are incompatible.
|
|
Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
|
Types of parameters 'x' and 'x' are incompatible.
|
|
Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/genericSpecializations3.ts(28,1): error TS2323: Type 'StringFoo2' is not assignable to type 'IntFoo'.
|
|
Types of property 'foo' are incompatible.
|
|
Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
|
Types of parameters 'x' and 'x' are incompatible.
|
|
Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/genericSpecializations3.ts(29,1): error TS2323: Type 'IntFoo' is not assignable to type 'StringFoo2'.
|
|
Types of property 'foo' are incompatible.
|
|
Type '(x: number) => number' is not assignable to type '(x: string) => string'.
|
|
Types of parameters 'x' and 'x' are incompatible.
|
|
Type 'number' is not assignable to type 'string'.
|
|
|
|
|
|
==== tests/cases/compiler/genericSpecializations3.ts (3 errors) ====
|
|
interface IFoo<T> {
|
|
foo(x: T): T;
|
|
}
|
|
|
|
var iFoo: IFoo<number>;
|
|
iFoo.foo(1);
|
|
|
|
class IntFooBad implements IFoo<number> { // error
|
|
~~~~~~~~~
|
|
!!! error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo<number>'.
|
|
!!! error TS2420: Types of property 'foo' are incompatible.
|
|
!!! error TS2420: Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
|
!!! error TS2420: Types of parameters 'x' and 'x' are incompatible.
|
|
!!! error TS2420: Type 'string' is not assignable to type 'number'.
|
|
foo(x: string): string { return null; }
|
|
}
|
|
|
|
var intFooBad: IntFooBad;
|
|
|
|
class IntFoo implements IFoo<number> {
|
|
foo(x: number): number { return null; }
|
|
}
|
|
|
|
var intFoo: IntFoo;
|
|
|
|
class StringFoo2 implements IFoo<string> {
|
|
foo(x: string): string { return null; }
|
|
}
|
|
|
|
var stringFoo2: StringFoo2;
|
|
stringFoo2.foo("hm");
|
|
|
|
|
|
intFoo = stringFoo2; // error
|
|
~~~~~~
|
|
!!! error TS2323: Type 'StringFoo2' is not assignable to type 'IntFoo'.
|
|
!!! error TS2323: Types of property 'foo' are incompatible.
|
|
!!! error TS2323: Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
|
!!! error TS2323: Types of parameters 'x' and 'x' are incompatible.
|
|
!!! error TS2323: Type 'string' is not assignable to type 'number'.
|
|
stringFoo2 = intFoo; // error
|
|
~~~~~~~~~~
|
|
!!! error TS2323: Type 'IntFoo' is not assignable to type 'StringFoo2'.
|
|
!!! error TS2323: Types of property 'foo' are incompatible.
|
|
!!! error TS2323: Type '(x: number) => number' is not assignable to type '(x: string) => string'.
|
|
!!! error TS2323: Types of parameters 'x' and 'x' are incompatible.
|
|
!!! error TS2323: Type 'number' is not assignable to type 'string'.
|
|
|
|
|
|
class StringFoo3 implements IFoo<string> { // error
|
|
foo<T>(x: T): T { return null; }
|
|
}
|
|
var stringFoo3: StringFoo3; |