Skip to content

Commit 93e0cfe

Browse files
committed
add test
1 parent b2cd48b commit 93e0cfe

5 files changed

+79
-0
lines changed
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [firstMatchRegExpMatchArray.ts]
2+
const match = ''.match(/ /)
3+
4+
if (match !== null) {
5+
const foo: string = match[0]
6+
const bar: string = match[1]
7+
}
8+
9+
10+
//// [firstMatchRegExpMatchArray.js]
11+
"use strict";
12+
var match = ''.match(/ /);
13+
if (match !== null) {
14+
var foo = match[0];
15+
var bar = match[1];
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/firstMatchRegExpMatchArray.ts ===
2+
const match = ''.match(/ /)
3+
>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5))
4+
>''.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --))
5+
>match : Symbol(String.match, Decl(lib.es5.d.ts, --, --))
6+
7+
if (match !== null) {
8+
>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5))
9+
10+
const foo: string = match[0]
11+
>foo : Symbol(foo, Decl(firstMatchRegExpMatchArray.ts, 3, 9))
12+
>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5))
13+
>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --))
14+
15+
const bar: string = match[1]
16+
>bar : Symbol(bar, Decl(firstMatchRegExpMatchArray.ts, 4, 9))
17+
>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5))
18+
}
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/firstMatchRegExpMatchArray.ts ===
2+
const match = ''.match(/ /)
3+
>match : RegExpMatchArray | null
4+
>''.match(/ /) : RegExpMatchArray | null
5+
>''.match : (regexp: string | RegExp) => RegExpMatchArray | null
6+
>'' : ""
7+
>match : (regexp: string | RegExp) => RegExpMatchArray | null
8+
>/ / : RegExp
9+
10+
if (match !== null) {
11+
>match !== null : boolean
12+
>match : RegExpMatchArray | null
13+
>null : null
14+
15+
const foo: string = match[0]
16+
>foo : string
17+
>match[0] : string
18+
>match : RegExpMatchArray
19+
>0 : 0
20+
21+
const bar: string = match[1]
22+
>bar : string
23+
>match[1] : string | undefined
24+
>match : RegExpMatchArray
25+
>1 : 1
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// @strict: true
12
// @noUncheckedIndexedAccess: true
23

34
const match = ''.match(/ /)
45

56
if (match !== null) {
67
const foo: string = match[0]
8+
const bar: string = match[1]
79
}

0 commit comments

Comments
 (0)