Skip to content

Commit e363198

Browse files
committed
Add regression tests
1 parent 8fd5e4c commit e363198

File tree

5 files changed

+235
-0
lines changed

5 files changed

+235
-0
lines changed

tests/baselines/reference/unknownControlFlow.errors.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,33 @@ tests/cases/conformance/types/unknown/unknownControlFlow.ts(293,5): error TS2345
417417
value;
418418
}
419419
}
420+
421+
// Repro from #51009
422+
423+
type TypeA = {
424+
A: 'A',
425+
B: 'B',
426+
}
427+
428+
type TypeB = {
429+
A: 'A',
430+
B: 'B',
431+
C: 'C',
432+
}
433+
434+
type R<T extends keyof TypeA> =
435+
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
436+
437+
type R2<T extends PropertyKey> =
438+
T extends keyof TypeA ?
439+
T extends keyof TypeB ?
440+
[TypeA[T], TypeB[T]] : never: never
441+
442+
// Repro from #51041
443+
444+
type AB = "A" | "B"
445+
446+
function x<T_AB extends AB>(x: T_AB & undefined, y: any) {
447+
let r2: never = y as T_AB & undefined;
448+
}
420449

tests/baselines/reference/unknownControlFlow.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,35 @@ function doSomething2(value: unknown): void {
400400
value;
401401
}
402402
}
403+
404+
// Repro from #51009
405+
406+
type TypeA = {
407+
A: 'A',
408+
B: 'B',
409+
}
410+
411+
type TypeB = {
412+
A: 'A',
413+
B: 'B',
414+
C: 'C',
415+
}
416+
417+
type R<T extends keyof TypeA> =
418+
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
419+
420+
type R2<T extends PropertyKey> =
421+
T extends keyof TypeA ?
422+
T extends keyof TypeB ?
423+
[TypeA[T], TypeB[T]] : never: never
424+
425+
// Repro from #51041
426+
427+
type AB = "A" | "B"
428+
429+
function x<T_AB extends AB>(x: T_AB & undefined, y: any) {
430+
let r2: never = y as T_AB & undefined;
431+
}
403432

404433

405434
//// [unknownControlFlow.js]
@@ -742,6 +771,9 @@ function doSomething2(value) {
742771
value;
743772
}
744773
}
774+
function x(x, y) {
775+
var r2 = y;
776+
}
745777

746778

747779
//// [unknownControlFlow.d.ts]
@@ -801,3 +833,19 @@ declare function fx10(x: string | number, y: number): void;
801833
declare function SendBlob(encoding: unknown): void;
802834
declare function doSomething1<T extends unknown>(value: T): T;
803835
declare function doSomething2(value: unknown): void;
836+
type TypeA = {
837+
A: 'A';
838+
B: 'B';
839+
};
840+
type TypeB = {
841+
A: 'A';
842+
B: 'B';
843+
C: 'C';
844+
};
845+
type R<T extends keyof TypeA> = T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never;
846+
type R2<T extends PropertyKey> = T extends keyof TypeA ? T extends keyof TypeB ? [
847+
TypeA[T],
848+
TypeB[T]
849+
] : never : never;
850+
type AB = "A" | "B";
851+
declare function x<T_AB extends AB>(x: T_AB & undefined, y: any): void;

tests/baselines/reference/unknownControlFlow.symbols

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,79 @@ function doSomething2(value: unknown): void {
923923
}
924924
}
925925

926+
// Repro from #51009
927+
928+
type TypeA = {
929+
>TypeA : Symbol(TypeA, Decl(unknownControlFlow.ts, 400, 1))
930+
931+
A: 'A',
932+
>A : Symbol(A, Decl(unknownControlFlow.ts, 404, 14))
933+
934+
B: 'B',
935+
>B : Symbol(B, Decl(unknownControlFlow.ts, 405, 11))
936+
}
937+
938+
type TypeB = {
939+
>TypeB : Symbol(TypeB, Decl(unknownControlFlow.ts, 407, 1))
940+
941+
A: 'A',
942+
>A : Symbol(A, Decl(unknownControlFlow.ts, 409, 14))
943+
944+
B: 'B',
945+
>B : Symbol(B, Decl(unknownControlFlow.ts, 410, 11))
946+
947+
C: 'C',
948+
>C : Symbol(C, Decl(unknownControlFlow.ts, 411, 11))
949+
}
950+
951+
type R<T extends keyof TypeA> =
952+
>R : Symbol(R, Decl(unknownControlFlow.ts, 413, 1))
953+
>T : Symbol(T, Decl(unknownControlFlow.ts, 415, 7))
954+
>TypeA : Symbol(TypeA, Decl(unknownControlFlow.ts, 400, 1))
955+
956+
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
957+
>T : Symbol(T, Decl(unknownControlFlow.ts, 415, 7))
958+
>TypeB : Symbol(TypeB, Decl(unknownControlFlow.ts, 407, 1))
959+
>TypeA : Symbol(TypeA, Decl(unknownControlFlow.ts, 400, 1))
960+
>T : Symbol(T, Decl(unknownControlFlow.ts, 415, 7))
961+
>TypeB : Symbol(TypeB, Decl(unknownControlFlow.ts, 407, 1))
962+
>T : Symbol(T, Decl(unknownControlFlow.ts, 415, 7))
963+
964+
type R2<T extends PropertyKey> =
965+
>R2 : Symbol(R2, Decl(unknownControlFlow.ts, 416, 56))
966+
>T : Symbol(T, Decl(unknownControlFlow.ts, 418, 8))
967+
>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --))
968+
969+
T extends keyof TypeA ?
970+
>T : Symbol(T, Decl(unknownControlFlow.ts, 418, 8))
971+
>TypeA : Symbol(TypeA, Decl(unknownControlFlow.ts, 400, 1))
972+
973+
T extends keyof TypeB ?
974+
>T : Symbol(T, Decl(unknownControlFlow.ts, 418, 8))
975+
>TypeB : Symbol(TypeB, Decl(unknownControlFlow.ts, 407, 1))
976+
977+
[TypeA[T], TypeB[T]] : never: never
978+
>TypeA : Symbol(TypeA, Decl(unknownControlFlow.ts, 400, 1))
979+
>T : Symbol(T, Decl(unknownControlFlow.ts, 418, 8))
980+
>TypeB : Symbol(TypeB, Decl(unknownControlFlow.ts, 407, 1))
981+
>T : Symbol(T, Decl(unknownControlFlow.ts, 418, 8))
982+
983+
// Repro from #51041
984+
985+
type AB = "A" | "B"
986+
>AB : Symbol(AB, Decl(unknownControlFlow.ts, 421, 43))
987+
988+
function x<T_AB extends AB>(x: T_AB & undefined, y: any) {
989+
>x : Symbol(x, Decl(unknownControlFlow.ts, 425, 19))
990+
>T_AB : Symbol(T_AB, Decl(unknownControlFlow.ts, 427, 11))
991+
>AB : Symbol(AB, Decl(unknownControlFlow.ts, 421, 43))
992+
>x : Symbol(x, Decl(unknownControlFlow.ts, 427, 28))
993+
>T_AB : Symbol(T_AB, Decl(unknownControlFlow.ts, 427, 11))
994+
>y : Symbol(y, Decl(unknownControlFlow.ts, 427, 48))
995+
996+
let r2: never = y as T_AB & undefined;
997+
>r2 : Symbol(r2, Decl(unknownControlFlow.ts, 428, 7))
998+
>y : Symbol(y, Decl(unknownControlFlow.ts, 427, 48))
999+
>T_AB : Symbol(T_AB, Decl(unknownControlFlow.ts, 427, 11))
1000+
}
1001+

tests/baselines/reference/unknownControlFlow.types

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,56 @@ function doSomething2(value: unknown): void {
10251025
}
10261026
}
10271027

1028+
// Repro from #51009
1029+
1030+
type TypeA = {
1031+
>TypeA : { A: 'A'; B: 'B'; }
1032+
1033+
A: 'A',
1034+
>A : "A"
1035+
1036+
B: 'B',
1037+
>B : "B"
1038+
}
1039+
1040+
type TypeB = {
1041+
>TypeB : { A: 'A'; B: 'B'; C: 'C'; }
1042+
1043+
A: 'A',
1044+
>A : "A"
1045+
1046+
B: 'B',
1047+
>B : "B"
1048+
1049+
C: 'C',
1050+
>C : "C"
1051+
}
1052+
1053+
type R<T extends keyof TypeA> =
1054+
>R : R<T>
1055+
1056+
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
1057+
1058+
type R2<T extends PropertyKey> =
1059+
>R2 : R2<T>
1060+
1061+
T extends keyof TypeA ?
1062+
T extends keyof TypeB ?
1063+
[TypeA[T], TypeB[T]] : never: never
1064+
1065+
// Repro from #51041
1066+
1067+
type AB = "A" | "B"
1068+
>AB : "A" | "B"
1069+
1070+
function x<T_AB extends AB>(x: T_AB & undefined, y: any) {
1071+
>x : <T_AB extends AB>(x: T_AB & undefined, y: any) => void
1072+
>x : T_AB & undefined
1073+
>y : any
1074+
1075+
let r2: never = y as T_AB & undefined;
1076+
>r2 : never
1077+
>y as T_AB & undefined : T_AB & undefined
1078+
>y : any
1079+
}
1080+

tests/cases/conformance/types/unknown/unknownControlFlow.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,32 @@ function doSomething2(value: unknown): void {
402402
value;
403403
}
404404
}
405+
406+
// Repro from #51009
407+
408+
type TypeA = {
409+
A: 'A',
410+
B: 'B',
411+
}
412+
413+
type TypeB = {
414+
A: 'A',
415+
B: 'B',
416+
C: 'C',
417+
}
418+
419+
type R<T extends keyof TypeA> =
420+
T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never
421+
422+
type R2<T extends PropertyKey> =
423+
T extends keyof TypeA ?
424+
T extends keyof TypeB ?
425+
[TypeA[T], TypeB[T]] : never: never
426+
427+
// Repro from #51041
428+
429+
type AB = "A" | "B"
430+
431+
function x<T_AB extends AB>(x: T_AB & undefined, y: any) {
432+
let r2: never = y as T_AB & undefined;
433+
}

0 commit comments

Comments
 (0)