Skip to content

Commit 3b80ddc

Browse files
DetachHeadsandersn
andauthored
fix first match in RegExpMatchArray being possibly undefined when noUncheckedIndexedAccess is enabled (#49682)
* fix first match in `RegExpMatchArray` being possibly undefined when `noUncheckedIndexedAccess` is enabled * fix tests * add test Co-authored-by: DetachHead <[email protected]> Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 330e33c commit 3b80ddc

File tree

41 files changed

+244
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+244
-150
lines changed

src/lib/es5.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ interface RegExpMatchArray extends Array<string> {
925925
* A copy of the search string.
926926
*/
927927
input?: string;
928+
/**
929+
* The first match. This will always be present because `null` will be returned if there are no matches.
930+
*/
931+
0: string;
928932
}
929933

930934
interface RegExpExecArray extends Array<string> {

tests/baselines/reference/assignFromStringInterface2.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(48
1717
indexOf(searchString: string, position?: number): number;
1818
lastIndexOf(searchString: string, position?: number): number;
1919
localeCompare(that: string): number;
20-
match(regexp: string): string[];
21-
match(regexp: RegExp): string[];
20+
match(regexp: string): RegExpMatchArray;
21+
match(regexp: RegExp): RegExpMatchArray;
2222
replace(searchValue: string, replaceValue: string): string;
2323
replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string;
2424
replace(searchValue: RegExp, replaceValue: string): string;
@@ -44,11 +44,11 @@ tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(48
4444
var a: String;
4545
var b: NotString;
4646

47-
a = x;
48-
a = b;
47+
a = x;
48+
a = b;
4949

50-
b = a;
51-
b = x;
50+
b = a;
51+
b = x;
5252

5353
x = a; // expected error
5454
~

tests/baselines/reference/assignFromStringInterface2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ interface NotString {
1212
indexOf(searchString: string, position?: number): number;
1313
lastIndexOf(searchString: string, position?: number): number;
1414
localeCompare(that: string): number;
15-
match(regexp: string): string[];
16-
match(regexp: RegExp): string[];
15+
match(regexp: string): RegExpMatchArray;
16+
match(regexp: RegExp): RegExpMatchArray;
1717
replace(searchValue: string, replaceValue: string): string;
1818
replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string;
1919
replace(searchValue: RegExp, replaceValue: string): string;
@@ -39,11 +39,11 @@ var x = '';
3939
var a: String;
4040
var b: NotString;
4141

42-
a = x;
43-
a = b;
42+
a = x;
43+
a = b;
4444

45-
b = a;
46-
b = x;
45+
b = a;
46+
b = x;
4747

4848
x = a; // expected error
4949
x = b; // expected error

tests/baselines/reference/assignFromStringInterface2.symbols

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,37 @@ interface NotString {
4141
>localeCompare : Symbol(NotString.localeCompare, Decl(assignFromStringInterface2.ts, 11, 65))
4242
>that : Symbol(that, Decl(assignFromStringInterface2.ts, 12, 18))
4343

44-
match(regexp: string): string[];
45-
>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 36))
44+
match(regexp: string): RegExpMatchArray;
45+
>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 44))
4646
>regexp : Symbol(regexp, Decl(assignFromStringInterface2.ts, 13, 10))
47+
>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --))
4748

48-
match(regexp: RegExp): string[];
49-
>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 36))
49+
match(regexp: RegExp): RegExpMatchArray;
50+
>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 44))
5051
>regexp : Symbol(regexp, Decl(assignFromStringInterface2.ts, 14, 10))
5152
>RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
53+
>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --))
5254

5355
replace(searchValue: string, replaceValue: string): string;
54-
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
56+
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
5557
>searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 15, 12))
5658
>replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 15, 32))
5759

5860
replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string;
59-
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
61+
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
6062
>searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 16, 12))
6163
>replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 16, 32))
6264
>substring : Symbol(substring, Decl(assignFromStringInterface2.ts, 16, 48))
6365
>args : Symbol(args, Decl(assignFromStringInterface2.ts, 16, 66))
6466

6567
replace(searchValue: RegExp, replaceValue: string): string;
66-
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
68+
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
6769
>searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 17, 12))
6870
>RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
6971
>replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 17, 32))
7072

7173
replace(searchValue: RegExp, replaceValue: (substring: string, ...args: any[]) => string): string;
72-
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
74+
>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63))
7375
>searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 18, 12))
7476
>RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7577
>replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 18, 32))
@@ -147,19 +149,19 @@ var b: NotString;
147149
>b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3))
148150
>NotString : Symbol(NotString, Decl(assignFromStringInterface2.ts, 2, 1))
149151

150-
a = x;
152+
a = x;
151153
>a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3))
152154
>x : Symbol(x, Decl(assignFromStringInterface2.ts, 36, 3))
153155

154-
a = b;
156+
a = b;
155157
>a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3))
156158
>b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3))
157159

158-
b = a;
160+
b = a;
159161
>b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3))
160162
>a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3))
161163

162-
b = x;
164+
b = x;
163165
>b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3))
164166
>x : Symbol(x, Decl(assignFromStringInterface2.ts, 36, 3))
165167

tests/baselines/reference/assignFromStringInterface2.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ interface NotString {
3737
>localeCompare : (that: string) => number
3838
>that : string
3939

40-
match(regexp: string): string[];
41-
>match : { (regexp: string): string[]; (regexp: RegExp): string[]; }
40+
match(regexp: string): RegExpMatchArray;
41+
>match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; }
4242
>regexp : string
4343

44-
match(regexp: RegExp): string[];
45-
>match : { (regexp: string): string[]; (regexp: RegExp): string[]; }
44+
match(regexp: RegExp): RegExpMatchArray;
45+
>match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; }
4646
>regexp : RegExp
4747

4848
replace(searchValue: string, replaceValue: string): string;
@@ -137,22 +137,22 @@ var a: String;
137137
var b: NotString;
138138
>b : NotString
139139

140-
a = x;
140+
a = x;
141141
>a = x : string
142142
>a : String
143143
>x : string
144144

145-
a = b;
145+
a = b;
146146
>a = b : NotString
147147
>a : String
148148
>b : NotString
149149

150-
b = a;
150+
b = a;
151151
>b = a : String
152152
>b : NotString
153153
>a : String
154154

155-
b = x;
155+
b = x;
156156
>b = x : string
157157
>b : NotString
158158
>x : string

tests/baselines/reference/bestChoiceType.symbols

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
// Repro from #10041
33

44
(''.match(/ /) || []).map(s => s.toLowerCase());
5-
>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
5+
>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
66
>''.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --))
77
>match : Symbol(String.match, Decl(lib.es5.d.ts, --, --))
8-
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
8+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
99
>s : Symbol(s, Decl(bestChoiceType.ts, 2, 26))
10-
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
1110
>s : Symbol(s, Decl(bestChoiceType.ts, 2, 26))
12-
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
1311

1412
// Similar cases
1513

@@ -27,13 +25,11 @@ function f1() {
2725

2826
let z = y.map(s => s.toLowerCase());
2927
>z : Symbol(z, Decl(bestChoiceType.ts, 9, 7))
30-
>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
28+
>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3129
>y : Symbol(y, Decl(bestChoiceType.ts, 8, 7))
32-
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
30+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3331
>s : Symbol(s, Decl(bestChoiceType.ts, 9, 18))
34-
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
3532
>s : Symbol(s, Decl(bestChoiceType.ts, 9, 18))
36-
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
3733
}
3834

3935
function f2() {
@@ -51,12 +47,10 @@ function f2() {
5147

5248
let z = y.map(s => s.toLowerCase());
5349
>z : Symbol(z, Decl(bestChoiceType.ts, 15, 7))
54-
>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
50+
>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5551
>y : Symbol(y, Decl(bestChoiceType.ts, 14, 7))
56-
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
52+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5753
>s : Symbol(s, Decl(bestChoiceType.ts, 15, 18))
58-
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
5954
>s : Symbol(s, Decl(bestChoiceType.ts, 15, 18))
60-
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --))
6155
}
6256

tests/baselines/reference/bestChoiceType.types

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
// Repro from #10041
33

44
(''.match(/ /) || []).map(s => s.toLowerCase());
5-
>(''.match(/ /) || []).map(s => s.toLowerCase()) : string[]
6-
>(''.match(/ /) || []).map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
7-
>(''.match(/ /) || []) : RegExpMatchArray
8-
>''.match(/ /) || [] : RegExpMatchArray
5+
>(''.match(/ /) || []).map(s => s.toLowerCase()) : any[]
6+
>(''.match(/ /) || []).map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
7+
>(''.match(/ /) || []) : RegExpMatchArray | []
8+
>''.match(/ /) || [] : RegExpMatchArray | []
99
>''.match(/ /) : RegExpMatchArray | null
1010
>''.match : (regexp: string | RegExp) => RegExpMatchArray | null
1111
>'' : ""
1212
>match : (regexp: string | RegExp) => RegExpMatchArray | null
1313
>/ / : RegExp
14-
>[] : never[]
15-
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
16-
>s => s.toLowerCase() : (s: string) => string
17-
>s : string
18-
>s.toLowerCase() : string
19-
>s.toLowerCase : () => string
20-
>s : string
21-
>toLowerCase : () => string
14+
>[] : []
15+
>map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
16+
>s => s.toLowerCase() : (s: any) => any
17+
>s : any
18+
>s.toLowerCase() : any
19+
>s.toLowerCase : any
20+
>s : any
21+
>toLowerCase : any
2222

2323
// Similar cases
2424

@@ -34,23 +34,23 @@ function f1() {
3434
>/ / : RegExp
3535

3636
let y = x || [];
37-
>y : RegExpMatchArray
38-
>x || [] : RegExpMatchArray
37+
>y : RegExpMatchArray | []
38+
>x || [] : RegExpMatchArray | []
3939
>x : RegExpMatchArray | null
40-
>[] : never[]
40+
>[] : []
4141

4242
let z = y.map(s => s.toLowerCase());
43-
>z : string[]
44-
>y.map(s => s.toLowerCase()) : string[]
45-
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
46-
>y : RegExpMatchArray
47-
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
48-
>s => s.toLowerCase() : (s: string) => string
49-
>s : string
50-
>s.toLowerCase() : string
51-
>s.toLowerCase : () => string
52-
>s : string
53-
>toLowerCase : () => string
43+
>z : any[]
44+
>y.map(s => s.toLowerCase()) : any[]
45+
>y.map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
46+
>y : RegExpMatchArray | []
47+
>map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
48+
>s => s.toLowerCase() : (s: any) => any
49+
>s : any
50+
>s.toLowerCase() : any
51+
>s.toLowerCase : any
52+
>s : any
53+
>toLowerCase : any
5454
}
5555

5656
function f2() {
@@ -65,23 +65,23 @@ function f2() {
6565
>/ / : RegExp
6666

6767
let y = x ? x : [];
68-
>y : RegExpMatchArray
69-
>x ? x : [] : RegExpMatchArray
68+
>y : RegExpMatchArray | never[]
69+
>x ? x : [] : RegExpMatchArray | never[]
7070
>x : RegExpMatchArray | null
7171
>x : RegExpMatchArray
7272
>[] : never[]
7373

7474
let z = y.map(s => s.toLowerCase());
75-
>z : string[]
76-
>y.map(s => s.toLowerCase()) : string[]
77-
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
78-
>y : RegExpMatchArray
79-
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
80-
>s => s.toLowerCase() : (s: string) => string
81-
>s : string
82-
>s.toLowerCase() : string
83-
>s.toLowerCase : () => string
84-
>s : string
85-
>toLowerCase : () => string
75+
>z : any[]
76+
>y.map(s => s.toLowerCase()) : any[]
77+
>y.map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
78+
>y : RegExpMatchArray | never[]
79+
>map : (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])
80+
>s => s.toLowerCase() : (s: any) => any
81+
>s : any
82+
>s.toLowerCase() : any
83+
>s.toLowerCase : any
84+
>s : any
85+
>toLowerCase : any
8686
}
8787

tests/baselines/reference/destructuringParameterDeclaration4.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
4141
a1(...array2); // Error parameter type is (number|string)[]
4242
~~~~~~
4343
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
44-
!!! related TS2728 /.ts/lib.es5.d.ts:1486:13: 'Array' is declared here.
44+
!!! related TS2728 /.ts/lib.es5.d.ts:1490:13: 'Array' is declared here.
4545
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
4646
~~~~~~~~
4747
!!! error TS2322: Type 'string' is not assignable to type '[[any]]'.

tests/baselines/reference/destructuringTuple.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
3333
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
3434
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
3535
!!! error TS2769: Target allows only 0 element(s) but source may have more.
36-
!!! related TS6502 /.ts/lib.es5.d.ts:1451:24: The expected type comes from the return type of this signature.
37-
!!! related TS6502 /.ts/lib.es5.d.ts:1457:27: The expected type comes from the return type of this signature.
36+
!!! related TS6502 /.ts/lib.es5.d.ts:1455:24: The expected type comes from the return type of this signature.
37+
!!! related TS6502 /.ts/lib.es5.d.ts:1461:27: The expected type comes from the return type of this signature.
3838
~~
3939
!!! error TS2769: No overload matches this call.
4040
!!! error TS2769: Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.

tests/baselines/reference/duplicateNumericIndexers.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tests/cases/conformance/types/members/duplicateNumericIndexers.ts(25,5): error T
1111
tests/cases/conformance/types/members/duplicateNumericIndexers.ts(29,5): error TS2374: Duplicate index signature for type 'number'.
1212
tests/cases/conformance/types/members/duplicateNumericIndexers.ts(30,5): error TS2374: Duplicate index signature for type 'number'.
1313
lib.es5.d.ts(517,5): error TS2374: Duplicate index signature for type 'number'.
14-
lib.es5.d.ts(1472,5): error TS2374: Duplicate index signature for type 'number'.
14+
lib.es5.d.ts(1476,5): error TS2374: Duplicate index signature for type 'number'.
1515

1616

1717
==== tests/cases/conformance/types/members/duplicateNumericIndexers.ts (12 errors) ====
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/firstMatchRegExpMatchArray.ts(5,11): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
2+
Type 'undefined' is not assignable to type 'string'.
3+
4+
5+
==== tests/cases/compiler/firstMatchRegExpMatchArray.ts (1 errors) ====
6+
const match = ''.match(/ /)
7+
8+
if (match !== null) {
9+
const foo: string = match[0]
10+
const bar: string = match[1]
11+
~~~
12+
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
13+
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
14+
}
15+

0 commit comments

Comments
 (0)