File: implementGenericWithMismatchedTypes.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download | duplicates (2)
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
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(7,7): error TS2420: 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 'T' is not assignable to type 'string'.
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(16,7): error TS2420: 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'.


==== 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
          ~
!!! error TS2420: Class 'C<T>' incorrectly implements interface 'IFoo<T>'.
!!! error TS2420:   Types of property 'foo' are incompatible.
!!! error TS2420:     Type '(x: string) => number' is not assignable to type '(x: T) => T'.
!!! error TS2420:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2420:         Type 'T' is not assignable to type 'string'.
        foo(x: string): number {
            return null;
        }
    }
    
    interface IFoo2<T> {
        foo(x: T): T;
    }
    class C2<T> implements IFoo2<T> { // error
          ~~
!!! error TS2420: Class 'C2<T>' incorrectly implements interface 'IFoo2<T>'.
!!! error TS2420:   Types of property 'foo' are incompatible.
!!! error TS2420:     Type '<Tstring>(x: Tstring) => number' is not assignable to type '(x: T) => T'.
!!! error TS2420:       Type 'number' is not assignable to type 'T'.
        foo<Tstring>(x: Tstring): number {
            return null;
        }
    }