File: propertyAccessOnTypeParameterWithConstraints3.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 (196 lines) | stat: -rw-r--r-- 4,583 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
=== tests/cases/conformance/types/typeParameters/typeParameterLists/propertyAccessOnTypeParameterWithConstraints3.ts ===
// generic types should behave as if they have properties of their constraint type

class A {
>A : A

    foo(): string { return ''; }
>foo : () => string
>'' : ""
}

class B extends A {
>B : B
>A : A

    bar(): string {
>bar : () => string

        return '';
>'' : ""
    }
}

class C<U extends A, T extends U> {
>C : C<U, T>

    f() {
>f : () => string

        var x: T;
>x : T

        // BUG 823818
        var a = x['foo'](); // should be string
>a : string
>x['foo']() : string
>x['foo'] : () => string
>x : T
>'foo' : "foo"

        return a + x.foo();
>a + x.foo() : string
>a : string
>x.foo() : string
>x.foo : () => string
>x : T
>foo : () => string
    }

    g(x: U) {
>g : (x: U) => string
>x : U

        // BUG 823818
        var a = x['foo'](); // should be string
>a : string
>x['foo']() : string
>x['foo'] : () => string
>x : U
>'foo' : "foo"

        return a + x.foo();
>a + x.foo() : string
>a : string
>x.foo() : string
>x.foo : () => string
>x : U
>foo : () => string
    }
}

var r1a = (new C<A, B>()).f();
>r1a : string
>(new C<A, B>()).f() : string
>(new C<A, B>()).f : () => string
>(new C<A, B>()) : C<A, B>
>new C<A, B>() : C<A, B>
>C : typeof C
>f : () => string

var r1b = (new C<A, B>()).g(new B());
>r1b : string
>(new C<A, B>()).g(new B()) : string
>(new C<A, B>()).g : (x: A) => string
>(new C<A, B>()) : C<A, B>
>new C<A, B>() : C<A, B>
>C : typeof C
>g : (x: A) => string
>new B() : B
>B : typeof B

interface I<U extends A, T extends U> {
    foo: T;
>foo : T
}
var i: I<A, B>;
>i : I<A, B>

var r2 = i.foo.foo();
>r2 : string
>i.foo.foo() : string
>i.foo.foo : () => string
>i.foo : B
>i : I<A, B>
>foo : B
>foo : () => string

var r2b = i.foo['foo']();
>r2b : string
>i.foo['foo']() : string
>i.foo['foo'] : () => string
>i.foo : B
>i : I<A, B>
>foo : B
>'foo' : "foo"

var a: {
>a : { <U extends A, T extends U>(): T; <U extends T, T extends A>(x: U): U; }

    <U extends A, T extends U>(): T;
    <U extends T, T extends A>(x: U): U;
>x : U
}
var r3 = a().foo(); // error, no inferences for U so it doesn't satisfy constraint
>r3 : string
>a().foo() : string
>a().foo : () => string
>a() : A
>a : { <U extends A, T extends U>(): T; <U extends T, T extends A>(x: U): U; }
>foo : () => string

var r3b = a()['foo']();
>r3b : string
>a()['foo']() : string
>a()['foo'] : () => string
>a() : A
>a : { <U extends A, T extends U>(): T; <U extends T, T extends A>(x: U): U; }
>'foo' : "foo"

// parameter supplied for type argument inference for U
var r3c = a(new B()).foo(); // valid call to an invalid function, U is inferred as B, which has a foo
>r3c : string
>a(new B()).foo() : string
>a(new B()).foo : () => string
>a(new B()) : B
>a : { <U extends A, T extends U>(): T; <U extends T, T extends A>(x: U): U; }
>new B() : B
>B : typeof B
>foo : () => string

var r3d = a(new B())['foo'](); // valid call to an invalid function, U is inferred as B, which has a foo
>r3d : string
>a(new B())['foo']() : string
>a(new B())['foo'] : () => string
>a(new B()) : B
>a : { <U extends A, T extends U>(): T; <U extends T, T extends A>(x: U): U; }
>new B() : B
>B : typeof B
>'foo' : "foo"

var b = {
>b : { foo: <U extends A, T extends U>(x: T) => string; }
>{    foo: <U extends A, T extends U>(x: T) => {        // BUG 823818        var a = x['foo'](); // should be string        return a + x.foo();    }} : { foo: <U extends A, T extends U>(x: T) => string; }

    foo: <U extends A, T extends U>(x: T) => {
>foo : <U extends A, T extends U>(x: T) => string
><U extends A, T extends U>(x: T) => {        // BUG 823818        var a = x['foo'](); // should be string        return a + x.foo();    } : <U extends A, T extends U>(x: T) => string
>x : T

        // BUG 823818
        var a = x['foo'](); // should be string
>a : string
>x['foo']() : string
>x['foo'] : () => string
>x : T
>'foo' : "foo"

        return a + x.foo();
>a + x.foo() : string
>a : string
>x.foo() : string
>x.foo : () => string
>x : T
>foo : () => string
    }
}

var r4 = b.foo(new B()); // valid call to an invalid function
>r4 : string
>b.foo(new B()) : string
>b.foo : <U extends A, T extends U>(x: T) => string
>b : { foo: <U extends A, T extends U>(x: T) => string; }
>foo : <U extends A, T extends U>(x: T) => string
>new B() : B
>B : typeof B