Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test around RegExp match vs. exec results #50813

Merged
merged 2 commits into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,9 +1,11 @@
error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without specifying option 'strictNullChecks'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(20,9): error TS2322: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray'.
Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.


!!! error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without specifying option 'strictNullChecks'.
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (0 errors) ====
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (1 errors) ====
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
matchResult[0].length;
matchResult[999].length;
matchResult.index + 0;
Expand All @@ -23,6 +25,9 @@ error TS5052: Option 'exactOptionalPropertyTypes' cannot be specified without sp
}
else {
execResult = matchResult
~~~~~~~~~~
!!! error TS2322: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray'.
!!! error TS2322: Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
}
}

@@ -1,5 +1,5 @@
//// [regexpExecAndMatchTypeUsages.ts]
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
matchResult[0].length;
matchResult[999].length;
matchResult.index + 0;
Expand Down
@@ -1,15 +1,15 @@
=== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts ===
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
>foo : Symbol(foo, Decl(regexpExecAndMatchTypeUsages.ts, 0, 0))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>RegExpExecArray : Symbol(RegExpExecArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>RegExpExecArray : Symbol(RegExpExecArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.regexp.d.ts, --, --))

matchResult[0].length;
>matchResult[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>0 : Symbol(RegExpExecArray[0], Decl(lib.es5.d.ts, --, --))
>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

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

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

matchResult.input.length;
>matchResult.input.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>matchResult.input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
>matchResult.input : Symbol(RegExpMatchArray.input, Decl(lib.es5.d.ts, --, --))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
>input : Symbol(RegExpMatchArray.input, Decl(lib.es5.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

matchResult.groups["someVariable"].length;
>matchResult.groups["someVariable"].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>matchResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>matchResult.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

matchResult.groups = undefined;
>matchResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>matchResult.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>undefined : Symbol(undefined)

execResult[0].length;
>execResult[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>0 : Symbol(RegExpExecArray[0], Decl(lib.es5.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

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

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

execResult.input.length;
>execResult.input.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>execResult.input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>input : Symbol(RegExpExecArray.input, Decl(lib.es5.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

execResult.groups["someVariable"].length;
>execResult.groups["someVariable"].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>execResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

execResult.groups = undefined;
>execResult.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>undefined : Symbol(undefined)

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

matchResult = execResult;
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
}
else {
execResult = matchResult
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 49))
>execResult : Symbol(execResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 50))
>matchResult : Symbol(matchResult, Decl(regexpExecAndMatchTypeUsages.ts, 0, 20))
}
}
Expand Down
@@ -1,50 +1,50 @@
=== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts ===
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
>foo : (matchResult: RegExpExecArray, execResult: RegExpExecArray) => void
>matchResult : RegExpExecArray
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
>foo : (matchResult: RegExpMatchArray, execResult: RegExpExecArray) => void
>matchResult : RegExpMatchArray
>execResult : RegExpExecArray

matchResult[0].length;
>matchResult[0].length : number
>matchResult[0] : string
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>0 : 0
>length : number

matchResult[999].length;
>matchResult[999].length : number
>matchResult[999] : string
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>999 : 999
>length : number

matchResult.index + 0;
>matchResult.index + 0 : number
>matchResult.index : number
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>index : number
>0 : 0

matchResult.input.length;
>matchResult.input.length : number
>matchResult.input : string
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>input : string
>length : number

matchResult.groups["someVariable"].length;
>matchResult.groups["someVariable"].length : number
>matchResult.groups["someVariable"] : string
>matchResult.groups : { [key: string]: string; }
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>groups : { [key: string]: string; }
>"someVariable" : "someVariable"
>length : number

matchResult.groups = undefined;
>matchResult.groups = undefined : undefined
>matchResult.groups : { [key: string]: string; }
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>groups : { [key: string]: string; }
>undefined : undefined

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

matchResult = execResult;
>matchResult = execResult : RegExpExecArray
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
>execResult : RegExpExecArray
}
else {
execResult = matchResult
>execResult = matchResult : RegExpExecArray
>execResult = matchResult : RegExpMatchArray
>execResult : RegExpExecArray
>matchResult : RegExpExecArray
>matchResult : RegExpMatchArray
}
}

@@ -1,24 +1,32 @@
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(3,5): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(4,5): error TS18048: 'matchResult.index' is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(5,5): error TS18048: 'matchResult.input' is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS18048: 'matchResult.groups' is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(6,5): error TS2532: Object is possibly 'undefined'.
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.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(10,5): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS18048: 'execResult.groups' is possibly 'undefined'.
tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(13,5): error TS2532: Object is possibly 'undefined'.
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.
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.
Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.


==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (8 errors) ====
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
==== tests/cases/compiler/regexpExecAndMatchTypeUsages.ts (11 errors) ====
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
matchResult[0].length;
matchResult[999].length;
~~~~~~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
matchResult.index + 0;
~~~~~~~~~~~~~~~~~
!!! error TS18048: 'matchResult.index' is possibly 'undefined'.
matchResult.input.length;
~~~~~~~~~~~~~~~~~
!!! error TS18048: 'matchResult.input' is possibly 'undefined'.
matchResult.groups["someVariable"].length;
~~~~~~~~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
!!! error TS18048: 'matchResult.groups' is possibly 'undefined'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
matchResult.groups = undefined;
Expand All @@ -33,7 +41,7 @@ tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(14,5): error TS2412: Type '
execResult.input.length;
execResult.groups["someVariable"].length;
~~~~~~~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
!!! error TS18048: 'execResult.groups' is possibly 'undefined'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
execResult.groups = undefined;
Expand All @@ -45,6 +53,9 @@ tests/cases/compiler/regexpExecAndMatchTypeUsages.ts(14,5): error TS2412: Type '
}
else {
execResult = matchResult
~~~~~~~~~~
!!! error TS2375: Type 'RegExpMatchArray' is not assignable to type 'RegExpExecArray' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sure is a weird error message since undefined doesn't show up at all in the source type. I would guess that this is a bug in exactOptionalPropertyTypes.

!!! error TS2375: Property 'index' is optional in type 'RegExpMatchArray' but required in type 'RegExpExecArray'.
}
}

@@ -1,5 +1,5 @@
//// [regexpExecAndMatchTypeUsages.ts]
export function foo(matchResult: RegExpExecArray, execResult: RegExpExecArray) {
export function foo(matchResult: RegExpMatchArray, execResult: RegExpExecArray) {
matchResult[0].length;
matchResult[999].length;
matchResult.index + 0;
Expand Down