@@ -7,6 +7,10 @@ class Shape {
7
7
visible : boolean ;
8
8
}
9
9
10
+ class TaggedShape extends Shape {
11
+ tag : string ;
12
+ }
13
+
10
14
class Item {
11
15
name : string ;
12
16
price : number ;
@@ -149,6 +153,17 @@ function f32<K extends "width" | "height">(key: K) {
149
153
return shape [ key ] ; // Shape[K]
150
154
}
151
155
156
+ function f33 < S extends Shape , K extends keyof S > (shape: S, key: K) {
157
+ let name = getProperty ( shape , "name" ) ;
158
+ let prop = getProperty ( shape , key ) ;
159
+ return prop ;
160
+ }
161
+
162
+ function f34 ( ts : TaggedShape ) {
163
+ let tag1 = f33 ( ts , "tag" ) ;
164
+ let tag2 = getProperty ( ts , "tag" ) ;
165
+ }
166
+
152
167
class C {
153
168
public x : string ;
154
169
protected y : string ;
@@ -164,14 +179,58 @@ function f40(c: C) {
164
179
let x : X = c [ "x" ] ;
165
180
let y : Y = c [ "y" ] ;
166
181
let z : Z = c [ "z" ] ;
182
+ }
183
+
184
+ // Repros from #12011
185
+
186
+ class Base {
187
+ get < K extends keyof this > (prop: K) {
188
+ return this [ prop ] ;
189
+ }
190
+ set< K extends keyof this > (prop: K, value: this[K]) {
191
+ this [ prop ] = value ;
192
+ }
193
+ }
194
+
195
+ class Person extends Base {
196
+ parts : number ;
197
+ constructor ( parts : number ) {
198
+ super ( ) ;
199
+ this . set ( "parts" , parts ) ;
200
+ }
201
+ getParts() {
202
+ return this . get ( "parts" )
203
+ }
204
+ }
205
+
206
+ class OtherPerson {
207
+ parts : number ;
208
+ constructor ( parts : number ) {
209
+ setProperty ( this , "parts" , parts ) ;
210
+ }
211
+ getParts() {
212
+ return getProperty ( this , "parts" )
213
+ }
167
214
}
168
215
169
216
//// [keyofAndIndexedAccess.js]
217
+ var __extends = ( this && this . __extends ) || function ( d , b ) {
218
+ for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ;
219
+ function __ ( ) { this . constructor = d ; }
220
+ d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
221
+ } ;
170
222
var Shape = (function () {
171
223
function Shape ( ) {
172
224
}
173
225
return Shape ;
174
226
} ());
227
+ var TaggedShape = (function (_super) {
228
+ __extends ( TaggedShape , _super ) ;
229
+ function TaggedShape ( ) {
230
+ return _super . apply ( this , arguments ) || this ;
231
+ }
232
+ return TaggedShape ;
233
+ } (Shape));
175
234
var Item = (function () {
176
235
function Item ( ) {
177
236
}
@@ -249,6 +308,15 @@ function f32(key) {
249
308
var shape = { name : "foo" , width : 5 , height : 10 , visible : true } ;
250
309
return shape [ key ] ; // Shape[K]
251
310
}
311
+ function f33(shape, key) {
312
+ var name = getProperty ( shape , "name" ) ;
313
+ var prop = getProperty ( shape , key ) ;
314
+ return prop ;
315
+ }
316
+ function f34(ts) {
317
+ var tag1 = f33 ( ts , "tag" ) ;
318
+ var tag2 = getProperty ( ts , "tag" ) ;
319
+ }
252
320
var C = (function () {
253
321
function C ( ) {
254
322
}
@@ -261,6 +329,39 @@ function f40(c) {
261
329
var y = c [ "y" ] ;
262
330
var z = c [ "z" ] ;
263
331
}
332
+ // Repros from #12011
333
+ var Base = (function () {
334
+ function Base ( ) {
335
+ }
336
+ Base . prototype . get = function ( prop ) {
337
+ return this [ prop ] ;
338
+ } ;
339
+ Base . prototype . set = function ( prop , value ) {
340
+ this [ prop ] = value ;
341
+ } ;
342
+ return Base ;
343
+ } ());
344
+ var Person = (function (_super) {
345
+ __extends ( Person , _super ) ;
346
+ function Person ( parts ) {
347
+ var _this = _super . call ( this ) || this ;
348
+ _this . set ( "parts" , parts ) ;
349
+ return _this ;
350
+ }
351
+ Person . prototype . getParts = function ( ) {
352
+ return this . get ( "parts" ) ;
353
+ } ;
354
+ return Person ;
355
+ } (Base));
356
+ var OtherPerson = (function () {
357
+ function OtherPerson ( parts ) {
358
+ setProperty ( this , "parts" , parts ) ;
359
+ }
360
+ OtherPerson . prototype . getParts = function ( ) {
361
+ return getProperty ( this , "parts" ) ;
362
+ } ;
363
+ return OtherPerson ;
364
+ } ());
264
365
265
366
266
367
//// [keyofAndIndexedAccess.d.ts]
@@ -270,6 +371,9 @@ declare class Shape {
270
371
height : number ;
271
372
visible : boolean ;
272
373
}
374
+ declare class TaggedShape extends Shape {
375
+ tag : string ;
376
+ }
273
377
declare class Item {
274
378
name : string ;
275
379
price : number ;
@@ -342,9 +446,25 @@ declare function pluck<T, K extends keyof T>(array: T[], key: K): T[K][];
342
446
declare function f30(shapes: Shape[]): void;
343
447
declare function f31< K extends keyof Shape > (key: K): Shape[K];
344
448
declare function f32< K extends "width " | "height "> (key: K): Shape[K];
449
+ declare function f33< S extends Shape , K extends keyof S > (shape: S, key: K): S[K];
450
+ declare function f34(ts: TaggedShape): void;
345
451
declare class C {
346
452
x : string ;
347
453
protected y : string ;
348
454
private z ;
349
455
}
350
456
declare function f40(c: C): void;
457
+ declare class Base {
458
+ get < K extends keyof this > ( prop : K ) : this [ K ] ;
459
+ set < K extends keyof this > ( prop : K , value : this [ K ] ) : void ;
460
+ }
461
+ declare class Person extends Base {
462
+ parts : number ;
463
+ constructor ( parts : number ) ;
464
+ getParts ( ) : number ;
465
+ }
466
+ declare class OtherPerson {
467
+ parts : number ;
468
+ constructor ( parts : number ) ;
469
+ getParts ( ) : number ;
470
+ }
0 commit comments