Skip to content

Commit 0df46e8

Browse files
authoredSep 16, 2022
Fix test around RegExp match vs. exec results (#50813)
* Fix up test. * Accepted baselines.
1 parent 2970c5d commit 0df46e8

9 files changed

+95
-79
lines changed
 

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=false).errors.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without specifying option 'strictNullChecks'.
2+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(20,9): error TS2322: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray'.
3+
Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
24

35

46
!!! error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without specifying option 'strictNullChecks'.
5-
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (0 errors) ====
6-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
7+
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (1 errors) ====
8+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
79
matchResult[0].length;
810
matchResult[999].length;
911
matchResult.index + 0;
@@ -23,6 +25,9 @@ error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without sp
2325
}
2426
else {
2527
execResult = matchResult
28+
~~~~~~~~~~
29+
!!! error TS2322: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray'.
30+
!!! error TS2322: Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
2631
}
2732
}
2833

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=false).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//// [regexpExecAndMatchTypeUsages.ts]
2-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
2+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
33
matchResult[0].length;
44
matchResult[999].length;
55
matchResult.index + 0;

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=false).symbols

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
=== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts ===
2-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
2+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
33
>foo : Symbol(foo, Decl(regexpExecAndMatchTypeUsages.ts, 0, 0))
44
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
5-
>RegExpExecArray : Symbol(RegExpExecArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))
6-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
5+
>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))
6+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
77
>RegExpExecArray : Symbol(RegExpExecArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))
88

99
matchResult[0].length;
1010
>matchResult[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
1111
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
12-
>0 : Symbol(RegExpExecArray[0], Decl(lib.es5.d.ts, --, --))
12+
>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --))
1313
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
1414

1515
matchResult[999].length;
@@ -18,63 +18,63 @@ export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
1818
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
1919

2020
matchResult.index + 0;
21-
>matchResult.index : Symbol(RegExpExecArray.index, Decl(lib.es5.d.ts, --, --))
21+
>matchResult.index : Symbol(RegExpMatchArray.index, Decl(lib.es5.d.ts, --, --))
2222
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
23-
>index : Symbol(RegExpExecArray.index, Decl(lib.es5.d.ts, --, --))
23+
>index : Symbol(RegExpMatchArray.index, Decl(lib.es5.d.ts, --, --))
2424

2525
matchResult.input.length;
2626
>matchResult.input.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
27-
>matchResult.input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
27+
>matchResult.input : Symbol(RegExpMatchArray.input, Decl(lib.es5.d.ts, --, --))
2828
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
29-
>input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
29+
>input : Symbol(RegExpMatchArray.input, Decl(lib.es5.d.ts, --, --))
3030
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
3131

3232
matchResult.groups["someVariable"].length;
3333
>matchResult.groups["someVariable"].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
34-
>matchResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
34+
>matchResult.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
3535
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
36-
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
36+
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
3737
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
3838

3939
matchResult.groups = undefined;
40-
>matchResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
40+
>matchResult.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
4141
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
42-
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
42+
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
4343
>undefined : Symbol(undefined)
4444

4545
execResult[0].length;
4646
>execResult[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
47-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
47+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
4848
>0 : Symbol(RegExpExecArray[0], Decl(lib.es5.d.ts, --, --))
4949
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
5050

5151
execResult[999].length;
5252
>execResult[999].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
53-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
53+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
5454
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
5555

5656
execResult.index + 0;
5757
>execResult.index : Symbol(RegExpExecArray.index, Decl(lib.es5.d.ts, --, --))
58-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
58+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
5959
>index : Symbol(RegExpExecArray.index, Decl(lib.es5.d.ts, --, --))
6060

6161
execResult.input.length;
6262
>execResult.input.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
6363
>execResult.input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
64-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
64+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
6565
>input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
6666
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
6767

6868
execResult.groups["someVariable"].length;
6969
>execResult.groups["someVariable"].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
7070
>execResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
71-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
71+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
7272
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
7373
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
7474

7575
execResult.groups = undefined;
7676
>execResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
77-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
77+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
7878
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
7979
>undefined : Symbol(undefined)
8080

@@ -85,11 +85,11 @@ export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
8585

8686
matchResult = execResult;
8787
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
88-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
88+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
8989
}
9090
else {
9191
execResult = matchResult
92-
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
92+
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
9393
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
9494
}
9595
}

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=false).types

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
=== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts ===
2-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
3-
>foo : (matchResult: RegExpExecArray, execResult: RegExpExecArray) => void
4-
>matchResult : RegExpExecArray
2+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
3+
>foo : (matchResult: RegExpMatchArray, execResult: RegExpExecArray) => void
4+
>matchResult : RegExpMatchArray
55
>execResult : RegExpExecArray
66

77
matchResult[0].length;
88
>matchResult[0].length : number
99
>matchResult[0] : string
10-
>matchResult : RegExpExecArray
10+
>matchResult : RegExpMatchArray
1111
>0 : 0
1212
>length : number
1313

1414
matchResult[999].length;
1515
>matchResult[999].length : number
1616
>matchResult[999] : string
17-
>matchResult : RegExpExecArray
17+
>matchResult : RegExpMatchArray
1818
>999 : 999
1919
>length : number
2020

2121
matchResult.index + 0;
2222
>matchResult.index + 0 : number
2323
>matchResult.index : number
24-
>matchResult : RegExpExecArray
24+
>matchResult : RegExpMatchArray
2525
>index : number
2626
>0 : 0
2727

2828
matchResult.input.length;
2929
>matchResult.input.length : number
3030
>matchResult.input : string
31-
>matchResult : RegExpExecArray
31+
>matchResult : RegExpMatchArray
3232
>input : string
3333
>length : number
3434

3535
matchResult.groups["someVariable"].length;
3636
>matchResult.groups["someVariable"].length : number
3737
>matchResult.groups["someVariable"] : string
3838
>matchResult.groups : { [key: string]: string; }
39-
>matchResult : RegExpExecArray
39+
>matchResult : RegExpMatchArray
4040
>groups : { [key: string]: string; }
4141
>"someVariable" : "someVariable"
4242
>length : number
4343

4444
matchResult.groups = undefined;
4545
>matchResult.groups = undefined : undefined
4646
>matchResult.groups : { [key: string]: string; }
47-
>matchResult : RegExpExecArray
47+
>matchResult : RegExpMatchArray
4848
>groups : { [key: string]: string; }
4949
>undefined : undefined
5050

@@ -100,14 +100,14 @@ export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
100100

101101
matchResult = execResult;
102102
>matchResult = execResult : RegExpExecArray
103-
>matchResult : RegExpExecArray
103+
>matchResult : RegExpMatchArray
104104
>execResult : RegExpExecArray
105105
}
106106
else {
107107
execResult = matchResult
108-
>execResult = matchResult : RegExpExecArray
108+
>execResult = matchResult : RegExpMatchArray
109109
>execResult : RegExpExecArray
110-
>matchResult : RegExpExecArray
110+
>matchResult : RegExpMatchArray
111111
}
112112
}
113113

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=true).errors.txt

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(3,5): error TS2532: Object is possibly 'undefined'.
2-
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS2532: Object is possibly 'undefined'.
2+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(4,5): error TS18048: 'matchResult.index' is possibly 'undefined'.
3+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(5,5): error TS18048: 'matchResult.input' is possibly 'undefined'.
4+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS18048: 'matchResult.groups' is possibly 'undefined'.
35
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS2532: Object is possibly 'undefined'.
46
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(7,5): error TS2412: Type 'undefined' is not assignable to type '{ [key: string]: string; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.
57
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(10,5): error TS2532: Object is possibly 'undefined'.
6-
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS2532: Object is possibly 'undefined'.
8+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS18048: 'execResult.groups' is possibly 'undefined'.
79
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS2532: Object is possibly 'undefined'.
810
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(14,5): error TS2412: Type 'undefined' is not assignable to type '{ [key: string]: string; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.
11+
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(20,9): error TS2375: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
12+
Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
913

1014

11-
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (8 errors) ====
12-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
15+
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (11 errors) ====
16+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
1317
matchResult[0].length;
1418
matchResult[999].length;
1519
~~~~~~~~~~~~~~~~
1620
!!! error TS2532: Object is possibly 'undefined'.
1721
matchResult.index + 0;
22+
~~~~~~~~~~~~~~~~~
23+
!!! error TS18048: 'matchResult.index' is possibly 'undefined'.
1824
matchResult.input.length;
25+
~~~~~~~~~~~~~~~~~
26+
!!! error TS18048: 'matchResult.input' is possibly 'undefined'.
1927
matchResult.groups["someVariable"].length;
2028
~~~~~~~~~~~~~~~~~~
21-
!!! error TS2532: Object is possibly 'undefined'.
29+
!!! error TS18048: 'matchResult.groups' is possibly 'undefined'.
2230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2331
!!! error TS2532: Object is possibly 'undefined'.
2432
matchResult.groups = undefined;
@@ -33,7 +41,7 @@ tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(14,5): error TS2412: Type '
3341
execResult.input.length;
3442
execResult.groups["someVariable"].length;
3543
~~~~~~~~~~~~~~~~~
36-
!!! error TS2532: Object is possibly 'undefined'.
44+
!!! error TS18048: 'execResult.groups' is possibly 'undefined'.
3745
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3846
!!! error TS2532: Object is possibly 'undefined'.
3947
execResult.groups = undefined;
@@ -45,6 +53,9 @@ tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(14,5): error TS2412: Type '
4553
}
4654
else {
4755
execResult = matchResult
56+
~~~~~~~~~~
57+
!!! error TS2375: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
58+
!!! error TS2375: Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
4859
}
4960
}
5061

‎tests/baselines/reference/regexpExecAndMatchTypeUsages(strict=true).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//// [regexpExecAndMatchTypeUsages.ts]
2-
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
2+
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
33
matchResult[0].length;
44
matchResult[999].length;
55
matchResult.index + 0;

0 commit comments

Comments
 (0)
Please sign in to comment.