Skip to content

Commit 0de8923

Browse files
committed
Add tests for mixed-length tuples used as rest
1 parent 46f2e57 commit 0de8923

8 files changed

+125
-0
lines changed

tests/baselines/reference/dependentDestructuredVariables.errors.txt

+8
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,12 @@ tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts(334,5): er
394394
}
395395
}
396396
}
397+
398+
// repros from #47190#issuecomment-1339753554
399+
const f70: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {
400+
if (type !== "one") x.toUpperCase();
401+
}
402+
const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {
403+
if (type !== "one") x.toUpperCase();
404+
}
397405

tests/baselines/reference/dependentDestructuredVariables.js

+19
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,14 @@ const fa3: (...args: [true, number] | [false, string]) => void = (guard, value)
386386
}
387387
}
388388
}
389+
390+
// repros from #47190#issuecomment-1339753554
391+
const f70: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {
392+
if (type !== "one") x.toUpperCase();
393+
}
394+
const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {
395+
if (type !== "one") x.toUpperCase();
396+
}
389397

390398

391399
//// [dependentDestructuredVariables.js]
@@ -687,6 +695,15 @@ const fa3 = (guard, value) => {
687695
}
688696
}
689697
};
698+
// repros from #47190#issuecomment-1339753554
699+
const f70 = (type, x) => {
700+
if (type !== "one")
701+
x.toUpperCase();
702+
};
703+
const f71 = (type, x) => {
704+
if (type !== "one")
705+
x.toUpperCase();
706+
};
690707

691708

692709
//// [dependentDestructuredVariables.d.ts]
@@ -827,3 +844,5 @@ declare function fa2(x: {
827844
value: string;
828845
}): void;
829846
declare const fa3: (...args: [true, number] | [false, string]) => void;
847+
declare const f70: (...args: [type: "one"] | [type: "two", x: string]) => void;
848+
declare const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void;

tests/baselines/reference/dependentDestructuredVariables.symbols

+26
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,29 @@ const fa3: (...args: [true, number] | [false, string]) => void = (guard, value)
965965
}
966966
}
967967

968+
// repros from #47190#issuecomment-1339753554
969+
const f70: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {
970+
>f70 : Symbol(f70, Decl(dependentDestructuredVariables.ts, 389, 5))
971+
>args : Symbol(args, Decl(dependentDestructuredVariables.ts, 389, 12))
972+
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 389, 74))
973+
>x : Symbol(x, Decl(dependentDestructuredVariables.ts, 389, 79))
974+
975+
if (type !== "one") x.toUpperCase();
976+
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 389, 74))
977+
>x.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
978+
>x : Symbol(x, Decl(dependentDestructuredVariables.ts, 389, 79))
979+
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
980+
}
981+
const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {
982+
>f71 : Symbol(f71, Decl(dependentDestructuredVariables.ts, 392, 5))
983+
>args : Symbol(args, Decl(dependentDestructuredVariables.ts, 392, 12))
984+
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 392, 86))
985+
>x : Symbol(x, Decl(dependentDestructuredVariables.ts, 392, 91))
986+
987+
if (type !== "one") x.toUpperCase();
988+
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 392, 86))
989+
>x.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
990+
>x : Symbol(x, Decl(dependentDestructuredVariables.ts, 392, 91))
991+
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
992+
}
993+

tests/baselines/reference/dependentDestructuredVariables.types

+34
Original file line numberDiff line numberDiff line change
@@ -1115,3 +1115,37 @@ const fa3: (...args: [true, number] | [false, string]) => void = (guard, value)
11151115
}
11161116
}
11171117

1118+
// repros from #47190#issuecomment-1339753554
1119+
const f70: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {
1120+
>f70 : (...args: [type: "one"] | [type: "two", x: string]) => void
1121+
>args : [type: "one"] | [type: "two", x: string]
1122+
>(type, x) => { if (type !== "one") x.toUpperCase();} : (type: "one" | "two", x: string | undefined) => void
1123+
>type : "one" | "two"
1124+
>x : string | undefined
1125+
1126+
if (type !== "one") x.toUpperCase();
1127+
>type !== "one" : boolean
1128+
>type : "one" | "two"
1129+
>"one" : "one"
1130+
>x.toUpperCase() : string
1131+
>x.toUpperCase : () => string
1132+
>x : string
1133+
>toUpperCase : () => string
1134+
}
1135+
const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {
1136+
>f71 : (...args: [type: "one", x?: number] | [type: "two", x: string]) => void
1137+
>args : [type: "one", x?: number | undefined] | [type: "two", x: string]
1138+
>(type, x) => { if (type !== "one") x.toUpperCase();} : (type: "one" | "two", x: string | number | undefined) => void
1139+
>type : "one" | "two"
1140+
>x : string | number | undefined
1141+
1142+
if (type !== "one") x.toUpperCase();
1143+
>type !== "one" : boolean
1144+
>type : "one" | "two"
1145+
>"one" : "one"
1146+
>x.toUpperCase() : string
1147+
>x.toUpperCase : () => string
1148+
>x : string
1149+
>toUpperCase : () => string
1150+
}
1151+

tests/baselines/reference/restTupleUnionWithRestContextualParams.symbols

+12
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ const f2: (x: string, ...args: [string] | [number, boolean]) => void = (a, b, c)
1414
>b : Symbol(b, Decl(restTupleUnionWithRestContextualParams.ts, 2, 74))
1515
>c : Symbol(c, Decl(restTupleUnionWithRestContextualParams.ts, 2, 77))
1616

17+
const f3: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {}
18+
>f3 : Symbol(f3, Decl(restTupleUnionWithRestContextualParams.ts, 4, 5))
19+
>args : Symbol(args, Decl(restTupleUnionWithRestContextualParams.ts, 4, 11))
20+
>type : Symbol(type, Decl(restTupleUnionWithRestContextualParams.ts, 4, 73))
21+
>x : Symbol(x, Decl(restTupleUnionWithRestContextualParams.ts, 4, 78))
22+
23+
const f4: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {}
24+
>f4 : Symbol(f4, Decl(restTupleUnionWithRestContextualParams.ts, 6, 5))
25+
>args : Symbol(args, Decl(restTupleUnionWithRestContextualParams.ts, 6, 11))
26+
>type : Symbol(type, Decl(restTupleUnionWithRestContextualParams.ts, 6, 85))
27+
>x : Symbol(x, Decl(restTupleUnionWithRestContextualParams.ts, 6, 90))
28+

tests/baselines/reference/restTupleUnionWithRestContextualParams.types

+14
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ const f2: (x: string, ...args: [string] | [number, boolean]) => void = (a, b, c)
1616
>b : string | number
1717
>c : boolean | undefined
1818

19+
const f3: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {}
20+
>f3 : (...args: [type: "one"] | [type: "two", x: string]) => void
21+
>args : [type: "one"] | [type: "two", x: string]
22+
>(type, x) => {} : (type: "one" | "two", x: string | undefined) => void
23+
>type : "one" | "two"
24+
>x : string | undefined
25+
26+
const f4: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {}
27+
>f4 : (...args: [type: "one", x?: number] | [type: "two", x: string]) => void
28+
>args : [type: "one", x?: number | undefined] | [type: "two", x: string]
29+
>(type, x) => {} : (type: "one" | "two", x: string | number | undefined) => void
30+
>type : "one" | "two"
31+
>x : string | number | undefined
32+

tests/cases/compiler/restTupleUnionWithRestContextualParams.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
const f1: (...args: [number, string, ...boolean[]] | [string, number, ...boolean[]]) => void = (a, b, c) => {};
55

66
const f2: (x: string, ...args: [string] | [number, boolean]) => void = (a, b, c) => {};
7+
8+
const f3: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {}
9+
10+
const f4: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {}

tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts

+8
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,11 @@ const fa3: (...args: [true, number] | [false, string]) => void = (guard, value)
390390
}
391391
}
392392
}
393+
394+
// repros from #47190#issuecomment-1339753554
395+
const f70: (...args: [type: "one"] | [type: "two", x: string]) => void = (type, x) => {
396+
if (type !== "one") x.toUpperCase();
397+
}
398+
const f71: (...args: [type: "one", x?: number] | [type: "two", x: string]) => void = (type, x) => {
399+
if (type !== "one") x.toUpperCase();
400+
}

0 commit comments

Comments
 (0)