@@ -426,3 +426,152 @@ const t2_55033 = factory_55033((a: { test: number }, b: string) => {})(
426
426
427
427
"some string"
428
428
);
429
+
430
+ // Same with non-readonly constraint
431
+
432
+ function factory_55033_2<const T extends unknown[]>(cb: (...args: T) => void) {
433
+ >factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
434
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))
435
+ >cb : Symbol(cb, Decl(typeParameterConstModifiers.ts, 127, 52))
436
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 127, 57))
437
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))
438
+
439
+ return function call<const K extends T>(...args: K): K {
440
+ >call : Symbol(call, Decl(typeParameterConstModifiers.ts, 128, 10))
441
+ >K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
442
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))
443
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 128, 44))
444
+ >K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
445
+ >K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
446
+
447
+ return {} as K;
448
+ >K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
449
+
450
+ };
451
+ }
452
+
453
+ const t1_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
454
+ >t1_55033_2 : Symbol(t1_55033_2, Decl(typeParameterConstModifiers.ts, 133, 5))
455
+ >factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
456
+ >a : Symbol(a, Decl(typeParameterConstModifiers.ts, 133, 36))
457
+ >test : Symbol(test, Decl(typeParameterConstModifiers.ts, 133, 40))
458
+ >b : Symbol(b, Decl(typeParameterConstModifiers.ts, 133, 56))
459
+
460
+ { test: 123 },
461
+ >test : Symbol(test, Decl(typeParameterConstModifiers.ts, 134, 5))
462
+
463
+ "some string"
464
+ );
465
+
466
+ const t2_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
467
+ >t2_55033_2 : Symbol(t2_55033_2, Decl(typeParameterConstModifiers.ts, 138, 5))
468
+ >factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
469
+ >a : Symbol(a, Decl(typeParameterConstModifiers.ts, 138, 36))
470
+ >test : Symbol(test, Decl(typeParameterConstModifiers.ts, 138, 40))
471
+ >b : Symbol(b, Decl(typeParameterConstModifiers.ts, 138, 56))
472
+
473
+ { test: 123 } as const,
474
+ >test : Symbol(test, Decl(typeParameterConstModifiers.ts, 139, 5))
475
+ >const : Symbol(const)
476
+
477
+ "some string"
478
+ );
479
+
480
+ // Repro from https://github.com/microsoft/TypeScript/issues/51931
481
+
482
+ declare function fn<const T extends any[]>(...args: T): T;
483
+ >fn : Symbol(fn, Decl(typeParameterConstModifiers.ts, 141, 2))
484
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))
485
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 145, 43))
486
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))
487
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))
488
+
489
+ const a = fn("a", false);
490
+ >a : Symbol(a, Decl(typeParameterConstModifiers.ts, 147, 5))
491
+ >fn : Symbol(fn, Decl(typeParameterConstModifiers.ts, 141, 2))
492
+
493
+ // More examples of non-readonly constraints
494
+
495
+ declare function fa1<const T extends unknown[]>(args: T): T;
496
+ >fa1 : Symbol(fa1, Decl(typeParameterConstModifiers.ts, 147, 25))
497
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))
498
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 151, 48))
499
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))
500
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))
501
+
502
+ declare function fa2<const T extends readonly unknown[]>(args: T): T;
503
+ >fa2 : Symbol(fa2, Decl(typeParameterConstModifiers.ts, 151, 60))
504
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))
505
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 152, 57))
506
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))
507
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))
508
+
509
+ fa1(["hello", 42]);
510
+ >fa1 : Symbol(fa1, Decl(typeParameterConstModifiers.ts, 147, 25))
511
+
512
+ fa2(["hello", 42]);
513
+ >fa2 : Symbol(fa2, Decl(typeParameterConstModifiers.ts, 151, 60))
514
+
515
+ declare function fb1<const T extends unknown[]>(...args: T): T;
516
+ >fb1 : Symbol(fb1, Decl(typeParameterConstModifiers.ts, 155, 19))
517
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))
518
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 157, 48))
519
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))
520
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))
521
+
522
+ declare function fb2<const T extends readonly unknown[]>(...args: T): T;
523
+ >fb2 : Symbol(fb2, Decl(typeParameterConstModifiers.ts, 157, 63))
524
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))
525
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 158, 57))
526
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))
527
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))
528
+
529
+ fb1("hello", 42);
530
+ >fb1 : Symbol(fb1, Decl(typeParameterConstModifiers.ts, 155, 19))
531
+
532
+ fb2("hello", 42);
533
+ >fb2 : Symbol(fb2, Decl(typeParameterConstModifiers.ts, 157, 63))
534
+
535
+ declare function fc1<const T extends unknown[]>(f: (...args: T) => void, ...args: T): T;
536
+ >fc1 : Symbol(fc1, Decl(typeParameterConstModifiers.ts, 161, 17))
537
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
538
+ >f : Symbol(f, Decl(typeParameterConstModifiers.ts, 163, 48))
539
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 163, 52))
540
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
541
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 163, 72))
542
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
543
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
544
+
545
+ declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void, ...args: T): T;
546
+ >fc2 : Symbol(fc2, Decl(typeParameterConstModifiers.ts, 163, 88))
547
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
548
+ >f : Symbol(f, Decl(typeParameterConstModifiers.ts, 164, 57))
549
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 164, 61))
550
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
551
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 164, 81))
552
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
553
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
554
+
555
+ fc1((a: string, b: number) => {}, "hello", 42);
556
+ >fc1 : Symbol(fc1, Decl(typeParameterConstModifiers.ts, 161, 17))
557
+ >a : Symbol(a, Decl(typeParameterConstModifiers.ts, 166, 5))
558
+ >b : Symbol(b, Decl(typeParameterConstModifiers.ts, 166, 15))
559
+
560
+ fc2((a: string, b: number) => {}, "hello", 42);
561
+ >fc2 : Symbol(fc2, Decl(typeParameterConstModifiers.ts, 163, 88))
562
+ >a : Symbol(a, Decl(typeParameterConstModifiers.ts, 167, 5))
563
+ >b : Symbol(b, Decl(typeParameterConstModifiers.ts, 167, 15))
564
+
565
+ declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;
566
+ >fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 167, 47))
567
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
568
+ >foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 169, 38))
569
+ >args : Symbol(args, Decl(typeParameterConstModifiers.ts, 169, 59))
570
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
571
+ >T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
572
+
573
+ fn1({ foo: ["hello", 123] }, { foo: [true]});
574
+ >fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 167, 47))
575
+ >foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 171, 5))
576
+ >foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 171, 30))
577
+
0 commit comments