File: classExtendingClassLikeType.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 (70 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download | duplicates (7)
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
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(7,18): error TS2689: Cannot extend an interface 'Base'. Did you mean 'implements'?
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(45,18): error TS2508: No base constructor has the specified number of type arguments.
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(56,18): error TS2510: Base constructors must all have the same return type.


==== tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts (3 errors) ====
    interface Base<T, U> {
        x: T;
        y: U;
    }
    
    // Error, no Base constructor function
    class D0 extends Base<string, string> {
                     ~~~~
!!! error TS2689: Cannot extend an interface 'Base'. Did you mean 'implements'?
    }
    
    interface BaseConstructor {
        new (x: string, y: string): Base<string, string>;
        new <T>(x: T): Base<T, T>;
        new <T>(x: T, y: T): Base<T, T>;
        new <T, U>(x: T, y: U): Base<T, U>;
    }
    
    declare function getBase(): BaseConstructor;
    
    class D1 extends getBase() {
        constructor() {
            super("abc", "def");
            this.x = "x";
            this.y = "y";
        }
    }
    
    class D2 extends getBase() <number> {
        constructor() {
            super(10);
            super(10, 20);
            this.x = 1;
            this.y = 2;
        }
    }
    
    class D3 extends getBase() <string, number> {
        constructor() {
            super("abc", 42);
            this.x = "x";
            this.y = 2;
        }
    }
    
    // Error, no constructors with three type arguments
    class D4 extends getBase() <string, string, string> {
                     ~~~~~~~~~
!!! error TS2508: No base constructor has the specified number of type arguments.
    }
    
    interface BadBaseConstructor {
        new (x: string): Base<string, string>;
        new (x: number): Base<number, number>;
    }
    
    declare function getBadBase(): BadBaseConstructor;
    
    // Error, constructor return types differ
    class D5 extends getBadBase() {
                     ~~~~~~~~~~~~
!!! error TS2510: Base constructors must all have the same return type.
    }