@@ -401,18 +401,18 @@ function exampleConstraints() {
401
401
>a : Symbol(Parent.a, Decl(narrowGenericTypeByInstanceOf.ts, 151, 19))
402
402
>A : Symbol(A, Decl(narrowGenericTypeByInstanceOf.ts, 151, 15))
403
403
}
404
- class Child<B extends number > extends Parent<B> {
404
+ class Child<B extends 1 | 2 | 3 > extends Parent<B> {
405
405
>Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
406
406
>B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 154, 14))
407
407
>Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
408
408
>B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 154, 14))
409
409
410
410
b: B;
411
- >b : Symbol(Child.b, Decl(narrowGenericTypeByInstanceOf.ts, 154, 51 ))
411
+ >b : Symbol(Child.b, Decl(narrowGenericTypeByInstanceOf.ts, 154, 54 ))
412
412
>B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 154, 14))
413
413
}
414
414
415
- const objPass: Parent<number > = undefined as any;
415
+ const objPass: Parent<1 | 2 | 3 > = undefined as any;
416
416
>objPass : Symbol(objPass, Decl(narrowGenericTypeByInstanceOf.ts, 158, 7))
417
417
>Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
418
418
>undefined : Symbol(undefined)
@@ -421,21 +421,21 @@ function exampleConstraints() {
421
421
>objPass : Symbol(objPass, Decl(narrowGenericTypeByInstanceOf.ts, 158, 7))
422
422
>Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
423
423
424
- objPass;
424
+ objPass; // expect: Child<1 | 2 | 3>
425
425
>objPass : Symbol(objPass, Decl(narrowGenericTypeByInstanceOf.ts, 158, 7))
426
426
}
427
427
428
- const objFour : Parent<4 > = undefined as any;
429
- >objFour : Symbol(objFour , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
428
+ const obj12 : Parent<1 | 2 > = undefined as any;
429
+ >obj12 : Symbol(obj12 , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
430
430
>Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
431
431
>undefined : Symbol(undefined)
432
432
433
- if (objFour instanceof Child) {
434
- >objFour : Symbol(objFour , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
433
+ if (obj12 instanceof Child) {
434
+ >obj12 : Symbol(obj12 , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
435
435
>Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
436
436
437
- objFour;
438
- >objFour : Symbol(objFour , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
437
+ obj12; // expect: Child<1 | 2>
438
+ >obj12 : Symbol(obj12 , Decl(narrowGenericTypeByInstanceOf.ts, 163, 7))
439
439
}
440
440
441
441
const objFail: Parent<string> = undefined as any;
@@ -447,106 +447,145 @@ function exampleConstraints() {
447
447
>objFail : Symbol(objFail, Decl(narrowGenericTypeByInstanceOf.ts, 168, 7))
448
448
>Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
449
449
450
- objFail;
450
+ objFail; // Child<any>, since string and 1|2|3 have no overlap.
451
451
>objFail : Symbol(objFail, Decl(narrowGenericTypeByInstanceOf.ts, 168, 7))
452
452
}
453
+
454
+ const objRefine: Parent<number> = undefined as any;
455
+ >objRefine : Symbol(objRefine, Decl(narrowGenericTypeByInstanceOf.ts, 173, 7))
456
+ >Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
457
+ >undefined : Symbol(undefined)
458
+
459
+ if (objRefine instanceof Child) {
460
+ >objRefine : Symbol(objRefine, Decl(narrowGenericTypeByInstanceOf.ts, 173, 7))
461
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
462
+
463
+ objRefine; // expect: Child<1 | 2 | 3>
464
+ >objRefine : Symbol(objRefine, Decl(narrowGenericTypeByInstanceOf.ts, 173, 7))
465
+ }
466
+
467
+ const objRefine1234: Parent<1 | 2 | 3 | 4> = undefined as any;
468
+ >objRefine1234 : Symbol(objRefine1234, Decl(narrowGenericTypeByInstanceOf.ts, 178, 7))
469
+ >Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
470
+ >undefined : Symbol(undefined)
471
+
472
+ if (objRefine1234 instanceof Child) {
473
+ >objRefine1234 : Symbol(objRefine1234, Decl(narrowGenericTypeByInstanceOf.ts, 178, 7))
474
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
475
+
476
+ objRefine1234; // expect: Child<1 | 2 | 3>
477
+ >objRefine1234 : Symbol(objRefine1234, Decl(narrowGenericTypeByInstanceOf.ts, 178, 7))
478
+ }
479
+
480
+ const objOverlap: Parent<2 | 3 | 4 | 5> = undefined as any;
481
+ >objOverlap : Symbol(objOverlap, Decl(narrowGenericTypeByInstanceOf.ts, 183, 7))
482
+ >Parent : Symbol(Parent, Decl(narrowGenericTypeByInstanceOf.ts, 150, 31))
483
+ >undefined : Symbol(undefined)
484
+
485
+ if (objOverlap instanceof Child) {
486
+ >objOverlap : Symbol(objOverlap, Decl(narrowGenericTypeByInstanceOf.ts, 183, 7))
487
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 153, 3))
488
+
489
+ objOverlap; // ideally, Child<2 | 3>, but actually Child<any> since 2|3|4|5 is not a supertype of 1|2|3.
490
+ >objOverlap : Symbol(objOverlap, Decl(narrowGenericTypeByInstanceOf.ts, 183, 7))
491
+ }
453
492
}
454
493
455
494
function exampleUnrelated() {
456
- >exampleUnrelated : Symbol(exampleUnrelated, Decl(narrowGenericTypeByInstanceOf.ts, 172 , 1))
495
+ >exampleUnrelated : Symbol(exampleUnrelated, Decl(narrowGenericTypeByInstanceOf.ts, 187 , 1))
457
496
458
497
class Child<A, B> {
459
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
460
- >A : Symbol(A, Decl(narrowGenericTypeByInstanceOf.ts, 175 , 14))
461
- >B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 175 , 16))
498
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
499
+ >A : Symbol(A, Decl(narrowGenericTypeByInstanceOf.ts, 190 , 14))
500
+ >B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 190 , 16))
462
501
463
502
a: A;
464
- >a : Symbol(Child.a, Decl(narrowGenericTypeByInstanceOf.ts, 175 , 21))
465
- >A : Symbol(A, Decl(narrowGenericTypeByInstanceOf.ts, 175 , 14))
503
+ >a : Symbol(Child.a, Decl(narrowGenericTypeByInstanceOf.ts, 190 , 21))
504
+ >A : Symbol(A, Decl(narrowGenericTypeByInstanceOf.ts, 190 , 14))
466
505
467
506
b: B;
468
- >b : Symbol(Child.b, Decl(narrowGenericTypeByInstanceOf.ts, 176 , 9))
469
- >B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 175 , 16))
507
+ >b : Symbol(Child.b, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 9))
508
+ >B : Symbol(B, Decl(narrowGenericTypeByInstanceOf.ts, 190 , 16))
470
509
471
510
foo: number;
472
- >foo : Symbol(Child.foo, Decl(narrowGenericTypeByInstanceOf.ts, 177 , 9))
511
+ >foo : Symbol(Child.foo, Decl(narrowGenericTypeByInstanceOf.ts, 192 , 9))
473
512
}
474
513
475
514
const objA = { a: 5 };
476
- >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 181 , 7))
477
- >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 181 , 16))
515
+ >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
516
+ >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 16))
478
517
479
518
if (objA instanceof Child) {
480
- >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 181 , 7))
481
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
519
+ >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
520
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
482
521
483
522
objA; // Child<number, any>
484
- >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 181 , 7))
523
+ >objA : Symbol(objA, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
485
524
}
486
525
487
526
const objB = { b: "hello" };
488
- >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 186 , 7))
489
- >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 186 , 16))
527
+ >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
528
+ >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 16))
490
529
491
530
if (objB instanceof Child) {
492
- >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 186 , 7))
493
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
531
+ >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
532
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
494
533
495
534
objB; // Child<any, string>
496
- >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 186 , 7))
535
+ >objB : Symbol(objB, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
497
536
}
498
537
499
538
const objAB = { a: 5, b: "hello" };
500
- >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 7))
501
- >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 17))
502
- >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 23))
539
+ >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
540
+ >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 17))
541
+ >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 23))
503
542
504
543
if (objAB instanceof Child) {
505
- >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 7))
506
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
544
+ >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
545
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
507
546
508
547
objAB; // Child<number, string>
509
- >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 191 , 7))
548
+ >objAB : Symbol(objAB, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
510
549
}
511
550
512
551
const objAX = { a: 5, x: 7 };
513
- >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
514
- >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 17))
515
- >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 23))
552
+ >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 211 , 7))
553
+ >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 211 , 17))
554
+ >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 211 , 23))
516
555
517
556
if (objAX instanceof Child) {
518
- >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
519
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
557
+ >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 211 , 7))
558
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
520
559
521
560
objAX; // Child<number, any>
522
- >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 196 , 7))
561
+ >objAX : Symbol(objAX, Decl(narrowGenericTypeByInstanceOf.ts, 211 , 7))
523
562
}
524
563
525
564
const objBX = { b: "hello", x: 7 };
526
- >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
527
- >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 17))
528
- >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 29))
565
+ >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 216 , 7))
566
+ >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 216 , 17))
567
+ >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 216 , 29))
529
568
530
569
if (objBX instanceof Child) {
531
- >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
532
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
570
+ >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 216 , 7))
571
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
533
572
534
573
objBX; // Child<any, string>
535
- >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 201 , 7))
574
+ >objBX : Symbol(objBX, Decl(narrowGenericTypeByInstanceOf.ts, 216 , 7))
536
575
}
537
576
538
577
const objABX = { a: 5, b: "hello", x: 7 };
539
- >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
540
- >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 18))
541
- >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 24))
542
- >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 36))
578
+ >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 7))
579
+ >a : Symbol(a, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 18))
580
+ >b : Symbol(b, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 24))
581
+ >x : Symbol(x, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 36))
543
582
544
583
if (objABX instanceof Child) {
545
- >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
546
- >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 174 , 29))
584
+ >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 7))
585
+ >Child : Symbol(Child, Decl(narrowGenericTypeByInstanceOf.ts, 189 , 29))
547
586
548
587
objABX; // Child<number, string>
549
- >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 206 , 7))
588
+ >objABX : Symbol(objABX, Decl(narrowGenericTypeByInstanceOf.ts, 221 , 7))
550
589
}
551
590
}
552
591
0 commit comments