32 lines
No EOL
1.2 KiB
Text
32 lines
No EOL
1.2 KiB
Text
==== tests/cases/compiler/implementGenericWithMismatchedTypes.ts (2 errors) ====
|
|
// no errors because in the derived types the best common type for T's value is Object
|
|
// and that matches the original signature for assignability since we treat its T's as Object
|
|
|
|
interface IFoo<T> {
|
|
foo(x: T): T;
|
|
}
|
|
class C<T> implements IFoo<T> { // error
|
|
~
|
|
!!! Class 'C<T>' incorrectly implements interface 'IFoo<T>':
|
|
!!! Types of property 'foo' are incompatible:
|
|
!!! Type '(x: string) => number' is not assignable to type '(x: T) => T':
|
|
!!! Types of parameters 'x' and 'x' are incompatible:
|
|
!!! Type 'string' is not assignable to type 'T'.
|
|
foo(x: string): number {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
interface IFoo2<T> {
|
|
foo(x: T): T;
|
|
}
|
|
class C2<T> implements IFoo2<T> { // error
|
|
~~
|
|
!!! Class 'C2<T>' incorrectly implements interface 'IFoo2<T>':
|
|
!!! Types of property 'foo' are incompatible:
|
|
!!! Type '<Tstring>(x: Tstring) => number' is not assignable to type '(x: T) => T':
|
|
!!! Type 'number' is not assignable to type 'T'.
|
|
foo<Tstring>(x: Tstring): number {
|
|
return null;
|
|
}
|
|
} |