@@ -249,6 +249,53 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
249
249
let b = func ( { a : 1 , b : "hello" } , { a : 2 , b : true } , 'b' ) ; // string | boolean
250
250
}
251
251
252
+ function f80 < T extends { a : { x : any } } > ( obj : T ) {
253
+ let a1 = obj . a ; // { x: any }
254
+ let a2 = obj [ 'a' ] ; // { x: any }
255
+ let a3 = obj [ 'a' ] as T [ 'a' ] ; // T["a"]
256
+ let x1 = obj . a . x ; // any
257
+ let x2 = obj [ 'a' ] [ 'x' ] ; // any
258
+ let x3 = obj [ 'a' ] [ 'x' ] as T [ 'a' ] [ 'x' ] ; // T["a"]["x"]
259
+ }
260
+
261
+ function f81 < T extends { a : { x : any } } > (obj: T) {
262
+ return obj [ 'a' ] [ 'x' ] as T [ 'a' ] [ 'x' ] ;
263
+ }
264
+
265
+ function f82() {
266
+ let x1 = f81 ( { a : { x : "hello" } } ) ; // string
267
+ let x2 = f81 ( { a : { x : 42 } } ) ; // number
268
+ }
269
+
270
+ function f83< T extends { [ x : string ] : { x : any } } , K extends keyof T > (obj: T, key: K) {
271
+ return obj [ key ] [ 'x' ] as T [ K ] [ 'x' ] ;
272
+ }
273
+
274
+ function f84() {
275
+ let x1 = f83 ( { foo : { x : "hello" } } , "foo" ) ; // string
276
+ let x2 = f83 ( { bar : { x : 42 } } , "bar" ) ; // number
277
+ }
278
+
279
+ class C1 {
280
+ x : number ;
281
+ get < K extends keyof this > ( key : K ) {
282
+ return this [ key ] ;
283
+ }
284
+ set < K extends keyof this > ( key : K , value : this [ K ] ) {
285
+ this [ key ] = value ;
286
+ }
287
+ foo() {
288
+ let x1 = this . x ; // number
289
+ let x2 = this [ "x" ] ; // number
290
+ let x3 = this . get ( "x" ) ; // this["x"]
291
+ let x4 = getProperty ( this , "x" ) ; // this["x"]
292
+ this . x = 42 ;
293
+ this [ "x" ] = 42 ;
294
+ this . set ( "x" , 42 ) ;
295
+ setProperty ( this , "x" , 42 ) ;
296
+ }
297
+ }
298
+
252
299
// Repros from #12011
253
300
254
301
class Base {
@@ -353,7 +400,25 @@ interface Options2<Data, Computed> {
353
400
declare class Component2 < Data , Computed > {
354
401
constructor ( options : Options2 < Data , Computed > ) ;
355
402
get < K extends keyof Data | keyof Computed > ( key : K ) : ( Data & Computed ) [ K ] ;
356
- }
403
+ }
404
+
405
+ // Repro from #12651
406
+
407
+ type MethodDescriptor = {
408
+ name : string ;
409
+ args : any [ ] ;
410
+ returnValue : any ;
411
+ }
412
+
413
+ declare function dispatchMethod < M extends MethodDescriptor > ( name : M [ 'name' ] , args : M [ 'args' ] ) : M [ 'returnValue' ] ;
414
+
415
+ type SomeMethodDescriptor = {
416
+ name : "someMethod" ;
417
+ args : [ string , number ] ;
418
+ returnValue : string [ ] ;
419
+ }
420
+
421
+ let result = dispatchMethod < SomeMethodDescriptor > ( "someMethod" , [ "hello" , 35 ] ) ;
357
422
358
423
//// [keyofAndIndexedAccess.js]
359
424
var __extends = ( this && this . __extends ) || function ( d , b ) {
@@ -525,6 +590,49 @@ function f74(func) {
525
590
var a = func ( { a : 1 , b : "hello" } , { a : 2 , b : true } , 'a' ) ; // number
526
591
var b = func ( { a : 1 , b : "hello" } , { a : 2 , b : true } , 'b' ) ; // string | boolean
527
592
}
593
+ function f80 ( obj ) {
594
+ var a1 = obj . a ; // { x: any }
595
+ var a2 = obj [ 'a' ] ; // { x: any }
596
+ var a3 = obj [ 'a' ] ; // T["a"]
597
+ var x1 = obj . a . x ; // any
598
+ var x2 = obj [ 'a' ] [ 'x' ] ; // any
599
+ var x3 = obj [ 'a' ] [ 'x' ] ; // T["a"]["x"]
600
+ }
601
+ function f81 ( obj ) {
602
+ return obj [ 'a' ] [ 'x' ] ;
603
+ }
604
+ function f82 ( ) {
605
+ var x1 = f81 ( { a : { x : "hello" } } ) ; // string
606
+ var x2 = f81 ( { a : { x : 42 } } ) ; // number
607
+ }
608
+ function f83 ( obj , key ) {
609
+ return obj [ key ] [ 'x' ] ;
610
+ }
611
+ function f84 ( ) {
612
+ var x1 = f83 ( { foo : { x : "hello" } } , "foo" ) ; // string
613
+ var x2 = f83 ( { bar : { x : 42 } } , "bar" ) ; // number
614
+ }
615
+ var C1 = ( function ( ) {
616
+ function C1 ( ) {
617
+ }
618
+ C1 . prototype . get = function ( key ) {
619
+ return this [ key ] ;
620
+ } ;
621
+ C1 . prototype . set = function ( key , value ) {
622
+ this [ key ] = value ;
623
+ } ;
624
+ C1 . prototype . foo = function ( ) {
625
+ var x1 = this . x ; // number
626
+ var x2 = this [ "x" ] ; // number
627
+ var x3 = this . get ( "x" ) ; // this["x"]
628
+ var x4 = getProperty ( this , "x" ) ; // this["x"]
629
+ this . x = 42 ;
630
+ this [ "x" ] = 42 ;
631
+ this . set ( "x" , 42 ) ;
632
+ setProperty ( this , "x" , 42 ) ;
633
+ } ;
634
+ return C1 ;
635
+ } ( ) ) ;
528
636
// Repros from #12011
529
637
var Base = ( function ( ) {
530
638
function Base ( ) {
@@ -589,6 +697,7 @@ var c1 = new Component1({
589
697
}
590
698
} ) ;
591
699
c1 . get ( "hello" ) ;
700
+ var result = dispatchMethod ( "someMethod" , [ "hello" , 35 ] ) ;
592
701
593
702
594
703
//// [keyofAndIndexedAccess.d.ts]
@@ -701,19 +810,42 @@ declare function f71(func: <T, U>(x: T, y: U) => Partial<T & U>): void;
701
810
declare function f72 ( func : < T , U , K extends keyof T | keyof U > ( x : T , y : U , k : K ) => ( T & U ) [ K ] ) : void ;
702
811
declare function f73 ( func : < T , U , K extends keyof ( T & U ) > ( x : T , y : U , k : K ) => ( T & U ) [ K ] ) : void ;
703
812
declare function f74 ( func : < T , U , K extends keyof ( T | U ) > ( x : T , y : U , k : K ) => ( T | U ) [ K ] ) : void ;
813
+ declare function f80 < T extends {
814
+ a : {
815
+ x : any ;
816
+ } ;
817
+ } > ( obj : T ) : void ;
818
+ declare function f81 < T extends {
819
+ a : {
820
+ x : any ;
821
+ } ;
822
+ } > ( obj : T ) : T [ "a" ] [ "x" ] ;
823
+ declare function f82 ( ) : void ;
824
+ declare function f83 < T extends {
825
+ [ x : string ] : {
826
+ x : any ;
827
+ } ;
828
+ } , K extends keyof T > ( obj : T , key : K ) : T [ K ] [ "x" ] ;
829
+ declare function f84 ( ) : void ;
830
+ declare class C1 {
831
+ x : number ;
832
+ get < K extends keyof this > (key: K): this[K];
833
+ set< K extends keyof this > (key: K, value: this[K]): void;
834
+ foo(): void;
835
+ }
704
836
declare class Base {
705
837
get < K extends keyof this > (prop: K): this[K];
706
838
set< K extends keyof this > (prop: K, value: this[K]): void;
707
839
}
708
840
declare class Person extends Base {
709
841
parts : number ;
710
842
constructor ( parts : number ) ;
711
- getParts ( ) : number ;
843
+ getParts ( ) : this [ "parts" ] ;
712
844
}
713
845
declare class OtherPerson {
714
846
parts : number ;
715
847
constructor ( parts : number ) ;
716
- getParts ( ) : number ;
848
+ getParts ( ) : this [ "parts" ] ;
717
849
}
718
850
declare function path < T , K1 extends keyof T > (obj: T, key1: K1): T[K1];
719
851
declare function path< T , K1 extends keyof T , K2 extends keyof T [ K1 ] > (obj: T, key1: K1, key2: K2): T[K1][K2];
@@ -757,3 +889,15 @@ declare class Component2<Data, Computed> {
757
889
constructor ( options : Options2 < Data , Computed > ) ;
758
890
get < K extends keyof Data | keyof Computed > ( key : K ) : ( Data & Computed ) [ K ] ;
759
891
}
892
+ declare type MethodDescriptor = {
893
+ name : string ;
894
+ args : any [ ] ;
895
+ returnValue : any ;
896
+ } ;
897
+ declare function dispatchMethod < M extends MethodDescriptor > ( name : M [ 'name' ] , args : M [ 'args' ] ) : M [ 'returnValue' ] ;
898
+ declare type SomeMethodDescriptor = {
899
+ name : "someMethod" ;
900
+ args : [ string , number ] ;
901
+ returnValue : string [ ] ;
902
+ } ;
903
+ declare let result : string [ ] ;
0 commit comments