File: derivedGenericClassWithAny.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (102 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (5)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
=== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts ===
class C<T extends number> {
>C : C<T>

    x: T;
>x : T

    get X(): T { return null; }
>X : T
>null : null

    foo(): T {
>foo : () => T

        return null;
>null : null
    }
}

class D extends C<number> {
>D : D
>C : C<number>

    x: any;
>x : any

    get X(): any {
>X : any

        return null;
>null : null
    }
    foo(): any {
>foo : () => any

        return 1;
>1 : 1
    }

    static y: any;
>y : any

    static get Y(): any {
>Y : any

        return null;
>null : null
    }
    static bar(): any {
>bar : () => any

        return null;
>null : null
    }
}

// if D is a valid class definition than E is now not safe tranisitively through C
class E<T extends string> extends D {
>E : E<T>
>D : D

    x: T;
>x : T

    get X(): T { return ''; } // error
>X : T
>'' : ""

    foo(): T {
>foo : () => T

        return ''; // error
>'' : ""
    }
}

var c: C<number>;
>c : C<number>

var d: D;
>d : D

var e: E<string>;
>e : E<string>

c = d;
>c = d : D
>c : C<number>
>d : D

c = e;
>c = e : E<string>
>c : C<number>
>e : E<string>

var r = c.foo(); // e.foo would return string
>r : number
>c.foo() : number
>c.foo : () => number
>c : C<number>
>foo : () => number