File: extendAndImplementTheSameBaseType2.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (32 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download | duplicates (4)
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
tests/cases/compiler/extendAndImplementTheSameBaseType2.ts(7,7): error TS2720: Class 'D' incorrectly implements class 'C<number>'. Did you mean to extend 'C<number>' and inherit its members as a subclass?
  The types returned by 'bar()' are incompatible between these types.
    Type 'string' is not assignable to type 'number'.
tests/cases/compiler/extendAndImplementTheSameBaseType2.ts(12,5): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/compiler/extendAndImplementTheSameBaseType2.ts(16,5): error TS2322: Type 'string' is not assignable to type 'number'.


==== tests/cases/compiler/extendAndImplementTheSameBaseType2.ts (3 errors) ====
    class C<T> {
        foo: number
        bar(): T {
            return null;
        }
    }
    class D extends C<string> implements C<number> {
          ~
!!! error TS2720: Class 'D' incorrectly implements class 'C<number>'. Did you mean to extend 'C<number>' and inherit its members as a subclass?
!!! error TS2720:   The types returned by 'bar()' are incompatible between these types.
!!! error TS2720:     Type 'string' is not assignable to type 'number'.
        baz() { }
    }
    
    var d: D = new D();
    var r: string = d.foo;
        ~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
    var r2: number = d.foo;
    
    var r3: string = d.bar();
    var r4: number = d.bar();
        ~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.