diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index ebcbde3b23e5b..f4b499cd81691 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -925,6 +925,10 @@ interface RegExpMatchArray extends Array { * A copy of the search string. */ input?: string; + /** + * The first match. This will always be present because `null` will be returned if there are no matches. + */ + 0: string; } interface RegExpExecArray extends Array { diff --git a/tests/baselines/reference/assignFromStringInterface2.errors.txt b/tests/baselines/reference/assignFromStringInterface2.errors.txt index 0fc3284bf0046..9364465567900 100644 --- a/tests/baselines/reference/assignFromStringInterface2.errors.txt +++ b/tests/baselines/reference/assignFromStringInterface2.errors.txt @@ -17,8 +17,8 @@ tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(48 indexOf(searchString: string, position?: number): number; lastIndexOf(searchString: string, position?: number): number; localeCompare(that: string): number; - match(regexp: string): string[]; - match(regexp: RegExp): string[]; + match(regexp: string): RegExpMatchArray; + match(regexp: RegExp): RegExpMatchArray; replace(searchValue: string, replaceValue: string): string; replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; replace(searchValue: RegExp, replaceValue: string): string; @@ -44,11 +44,11 @@ tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(48 var a: String; var b: NotString; - a = x; - a = b; + a = x; + a = b; - b = a; - b = x; + b = a; + b = x; x = a; // expected error ~ diff --git a/tests/baselines/reference/assignFromStringInterface2.js b/tests/baselines/reference/assignFromStringInterface2.js index 5636a4806cc9e..ac8a3af66d5ee 100644 --- a/tests/baselines/reference/assignFromStringInterface2.js +++ b/tests/baselines/reference/assignFromStringInterface2.js @@ -12,8 +12,8 @@ interface NotString { indexOf(searchString: string, position?: number): number; lastIndexOf(searchString: string, position?: number): number; localeCompare(that: string): number; - match(regexp: string): string[]; - match(regexp: RegExp): string[]; + match(regexp: string): RegExpMatchArray; + match(regexp: RegExp): RegExpMatchArray; replace(searchValue: string, replaceValue: string): string; replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; replace(searchValue: RegExp, replaceValue: string): string; @@ -39,11 +39,11 @@ var x = ''; var a: String; var b: NotString; -a = x; -a = b; +a = x; +a = b; -b = a; -b = x; +b = a; +b = x; x = a; // expected error x = b; // expected error diff --git a/tests/baselines/reference/assignFromStringInterface2.symbols b/tests/baselines/reference/assignFromStringInterface2.symbols index c050922bc9844..6b49a36c5db9d 100644 --- a/tests/baselines/reference/assignFromStringInterface2.symbols +++ b/tests/baselines/reference/assignFromStringInterface2.symbols @@ -41,35 +41,37 @@ interface NotString { >localeCompare : Symbol(NotString.localeCompare, Decl(assignFromStringInterface2.ts, 11, 65)) >that : Symbol(that, Decl(assignFromStringInterface2.ts, 12, 18)) - match(regexp: string): string[]; ->match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 36)) + match(regexp: string): RegExpMatchArray; +>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 44)) >regexp : Symbol(regexp, Decl(assignFromStringInterface2.ts, 13, 10)) +>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --)) - match(regexp: RegExp): string[]; ->match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 36)) + match(regexp: RegExp): RegExpMatchArray; +>match : Symbol(NotString.match, Decl(assignFromStringInterface2.ts, 12, 40), Decl(assignFromStringInterface2.ts, 13, 44)) >regexp : Symbol(regexp, Decl(assignFromStringInterface2.ts, 14, 10)) >RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --)) replace(searchValue: string, replaceValue: string): string; ->replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) +>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) >searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 15, 12)) >replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 15, 32)) replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; ->replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) +>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) >searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 16, 12)) >replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 16, 32)) >substring : Symbol(substring, Decl(assignFromStringInterface2.ts, 16, 48)) >args : Symbol(args, Decl(assignFromStringInterface2.ts, 16, 66)) replace(searchValue: RegExp, replaceValue: string): string; ->replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) +>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) >searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 17, 12)) >RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 17, 32)) replace(searchValue: RegExp, replaceValue: (substring: string, ...args: any[]) => string): string; ->replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 36), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) +>replace : Symbol(NotString.replace, Decl(assignFromStringInterface2.ts, 14, 44), Decl(assignFromStringInterface2.ts, 15, 63), Decl(assignFromStringInterface2.ts, 16, 102), Decl(assignFromStringInterface2.ts, 17, 63)) >searchValue : Symbol(searchValue, Decl(assignFromStringInterface2.ts, 18, 12)) >RegExp : Symbol(RegExp, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >replaceValue : Symbol(replaceValue, Decl(assignFromStringInterface2.ts, 18, 32)) @@ -147,19 +149,19 @@ var b: NotString; >b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3)) >NotString : Symbol(NotString, Decl(assignFromStringInterface2.ts, 2, 1)) -a = x; +a = x; >a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3)) >x : Symbol(x, Decl(assignFromStringInterface2.ts, 36, 3)) -a = b; +a = b; >a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3)) >b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3)) -b = a; +b = a; >b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3)) >a : Symbol(a, Decl(assignFromStringInterface2.ts, 37, 3)) -b = x; +b = x; >b : Symbol(b, Decl(assignFromStringInterface2.ts, 38, 3)) >x : Symbol(x, Decl(assignFromStringInterface2.ts, 36, 3)) diff --git a/tests/baselines/reference/assignFromStringInterface2.types b/tests/baselines/reference/assignFromStringInterface2.types index 103fea902175b..800269ffca323 100644 --- a/tests/baselines/reference/assignFromStringInterface2.types +++ b/tests/baselines/reference/assignFromStringInterface2.types @@ -37,12 +37,12 @@ interface NotString { >localeCompare : (that: string) => number >that : string - match(regexp: string): string[]; ->match : { (regexp: string): string[]; (regexp: RegExp): string[]; } + match(regexp: string): RegExpMatchArray; +>match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; } >regexp : string - match(regexp: RegExp): string[]; ->match : { (regexp: string): string[]; (regexp: RegExp): string[]; } + match(regexp: RegExp): RegExpMatchArray; +>match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; } >regexp : RegExp replace(searchValue: string, replaceValue: string): string; @@ -137,22 +137,22 @@ var a: String; var b: NotString; >b : NotString -a = x; +a = x; >a = x : string >a : String >x : string -a = b; +a = b; >a = b : NotString >a : String >b : NotString -b = a; +b = a; >b = a : String >b : NotString >a : String -b = x; +b = x; >b = x : string >b : NotString >x : string diff --git a/tests/baselines/reference/bestChoiceType.symbols b/tests/baselines/reference/bestChoiceType.symbols index c7732890347d0..0072356223368 100644 --- a/tests/baselines/reference/bestChoiceType.symbols +++ b/tests/baselines/reference/bestChoiceType.symbols @@ -2,14 +2,12 @@ // Repro from #10041 (''.match(/ /) || []).map(s => s.toLowerCase()); ->(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >''.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) >match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) ->map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 2, 26)) ->s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 2, 26)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) // Similar cases @@ -27,13 +25,11 @@ function f1() { let z = y.map(s => s.toLowerCase()); >z : Symbol(z, Decl(bestChoiceType.ts, 9, 7)) ->y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(bestChoiceType.ts, 8, 7)) ->map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 9, 18)) ->s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 9, 18)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) } function f2() { @@ -51,12 +47,10 @@ function f2() { let z = y.map(s => s.toLowerCase()); >z : Symbol(z, Decl(bestChoiceType.ts, 15, 7)) ->y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>y.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(bestChoiceType.ts, 14, 7)) ->map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 15, 18)) ->s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(bestChoiceType.ts, 15, 18)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) } diff --git a/tests/baselines/reference/bestChoiceType.types b/tests/baselines/reference/bestChoiceType.types index 49997d1e273cc..05d77542f6cce 100644 --- a/tests/baselines/reference/bestChoiceType.types +++ b/tests/baselines/reference/bestChoiceType.types @@ -2,23 +2,23 @@ // Repro from #10041 (''.match(/ /) || []).map(s => s.toLowerCase()); ->(''.match(/ /) || []).map(s => s.toLowerCase()) : string[] ->(''.match(/ /) || []).map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->(''.match(/ /) || []) : RegExpMatchArray ->''.match(/ /) || [] : RegExpMatchArray +>(''.match(/ /) || []).map(s => s.toLowerCase()) : any[] +>(''.match(/ /) || []).map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>(''.match(/ /) || []) : RegExpMatchArray | [] +>''.match(/ /) || [] : RegExpMatchArray | [] >''.match(/ /) : RegExpMatchArray | null >''.match : (regexp: string | RegExp) => RegExpMatchArray | null >'' : "" >match : (regexp: string | RegExp) => RegExpMatchArray | null >/ / : RegExp ->[] : never[] ->map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->s => s.toLowerCase() : (s: string) => string ->s : string ->s.toLowerCase() : string ->s.toLowerCase : () => string ->s : string ->toLowerCase : () => string +>[] : [] +>map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>s => s.toLowerCase() : (s: any) => any +>s : any +>s.toLowerCase() : any +>s.toLowerCase : any +>s : any +>toLowerCase : any // Similar cases @@ -34,23 +34,23 @@ function f1() { >/ / : RegExp let y = x || []; ->y : RegExpMatchArray ->x || [] : RegExpMatchArray +>y : RegExpMatchArray | [] +>x || [] : RegExpMatchArray | [] >x : RegExpMatchArray | null ->[] : never[] +>[] : [] let z = y.map(s => s.toLowerCase()); ->z : string[] ->y.map(s => s.toLowerCase()) : string[] ->y.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->y : RegExpMatchArray ->map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->s => s.toLowerCase() : (s: string) => string ->s : string ->s.toLowerCase() : string ->s.toLowerCase : () => string ->s : string ->toLowerCase : () => string +>z : any[] +>y.map(s => s.toLowerCase()) : any[] +>y.map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>y : RegExpMatchArray | [] +>map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>s => s.toLowerCase() : (s: any) => any +>s : any +>s.toLowerCase() : any +>s.toLowerCase : any +>s : any +>toLowerCase : any } function f2() { @@ -65,23 +65,23 @@ function f2() { >/ / : RegExp let y = x ? x : []; ->y : RegExpMatchArray ->x ? x : [] : RegExpMatchArray +>y : RegExpMatchArray | never[] +>x ? x : [] : RegExpMatchArray | never[] >x : RegExpMatchArray | null >x : RegExpMatchArray >[] : never[] let z = y.map(s => s.toLowerCase()); ->z : string[] ->y.map(s => s.toLowerCase()) : string[] ->y.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->y : RegExpMatchArray ->map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] ->s => s.toLowerCase() : (s: string) => string ->s : string ->s.toLowerCase() : string ->s.toLowerCase : () => string ->s : string ->toLowerCase : () => string +>z : any[] +>y.map(s => s.toLowerCase()) : any[] +>y.map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>y : RegExpMatchArray | never[] +>map : ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) +>s => s.toLowerCase() : (s: any) => any +>s : any +>s.toLowerCase() : any +>s.toLowerCase : any +>s : any +>toLowerCase : any } diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index 23329497b28ff..bb7aff5eb0fc0 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'? -!!! related TS2728 /.ts/lib.es5.d.ts:1486:13: 'Array' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1490:13: 'Array' is declared here. a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] ~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type '[[any]]'. diff --git a/tests/baselines/reference/destructuringTuple.errors.txt b/tests/baselines/reference/destructuringTuple.errors.txt index b863a27a854f0..e8548783cafc4 100644 --- a/tests/baselines/reference/destructuringTuple.errors.txt +++ b/tests/baselines/reference/destructuringTuple.errors.txt @@ -33,8 +33,8 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat !!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error. !!! error TS2769: Type 'never[]' is not assignable to type '[]'. !!! error TS2769: Target allows only 0 element(s) but source may have more. -!!! related TS6502 /.ts/lib.es5.d.ts:1451:24: The expected type comes from the return type of this signature. -!!! related TS6502 /.ts/lib.es5.d.ts:1457:27: The expected type comes from the return type of this signature. +!!! related TS6502 /.ts/lib.es5.d.ts:1455:24: The expected type comes from the return type of this signature. +!!! related TS6502 /.ts/lib.es5.d.ts:1461:27: The expected type comes from the return type of this signature. ~~ !!! error TS2769: No overload matches this call. !!! error TS2769: Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. diff --git a/tests/baselines/reference/duplicateNumericIndexers.errors.txt b/tests/baselines/reference/duplicateNumericIndexers.errors.txt index 9bd8d221ef4f9..b149e6f586d06 100644 --- a/tests/baselines/reference/duplicateNumericIndexers.errors.txt +++ b/tests/baselines/reference/duplicateNumericIndexers.errors.txt @@ -11,7 +11,7 @@ tests/cases/conformance/types/members/duplicateNumericIndexers.ts(25,5): error T tests/cases/conformance/types/members/duplicateNumericIndexers.ts(29,5): error TS2374: Duplicate index signature for type 'number'. tests/cases/conformance/types/members/duplicateNumericIndexers.ts(30,5): error TS2374: Duplicate index signature for type 'number'. lib.es5.d.ts(517,5): error TS2374: Duplicate index signature for type 'number'. -lib.es5.d.ts(1472,5): error TS2374: Duplicate index signature for type 'number'. +lib.es5.d.ts(1476,5): error TS2374: Duplicate index signature for type 'number'. ==== tests/cases/conformance/types/members/duplicateNumericIndexers.ts (12 errors) ==== diff --git a/tests/baselines/reference/firstMatchRegExpMatchArray.errors.txt b/tests/baselines/reference/firstMatchRegExpMatchArray.errors.txt new file mode 100644 index 0000000000000..49c4177b2e215 --- /dev/null +++ b/tests/baselines/reference/firstMatchRegExpMatchArray.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/firstMatchRegExpMatchArray.ts(5,11): error TS2322: Type 'string | undefined' is not assignable to type 'string'. + Type 'undefined' is not assignable to type 'string'. + + +==== tests/cases/compiler/firstMatchRegExpMatchArray.ts (1 errors) ==== + const match = ''.match(/ /) + + if (match !== null) { + const foo: string = match[0] + const bar: string = match[1] + ~~~ +!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'. +!!! error TS2322: Type 'undefined' is not assignable to type 'string'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/firstMatchRegExpMatchArray.js b/tests/baselines/reference/firstMatchRegExpMatchArray.js new file mode 100644 index 0000000000000..5c1a0ab8af089 --- /dev/null +++ b/tests/baselines/reference/firstMatchRegExpMatchArray.js @@ -0,0 +1,16 @@ +//// [firstMatchRegExpMatchArray.ts] +const match = ''.match(/ /) + +if (match !== null) { + const foo: string = match[0] + const bar: string = match[1] +} + + +//// [firstMatchRegExpMatchArray.js] +"use strict"; +var match = ''.match(/ /); +if (match !== null) { + var foo = match[0]; + var bar = match[1]; +} diff --git a/tests/baselines/reference/firstMatchRegExpMatchArray.symbols b/tests/baselines/reference/firstMatchRegExpMatchArray.symbols new file mode 100644 index 0000000000000..39569bc41acf2 --- /dev/null +++ b/tests/baselines/reference/firstMatchRegExpMatchArray.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/firstMatchRegExpMatchArray.ts === +const match = ''.match(/ /) +>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5)) +>''.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) +>match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) + +if (match !== null) { +>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5)) + + const foo: string = match[0] +>foo : Symbol(foo, Decl(firstMatchRegExpMatchArray.ts, 3, 9)) +>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) + + const bar: string = match[1] +>bar : Symbol(bar, Decl(firstMatchRegExpMatchArray.ts, 4, 9)) +>match : Symbol(match, Decl(firstMatchRegExpMatchArray.ts, 0, 5)) +} + diff --git a/tests/baselines/reference/firstMatchRegExpMatchArray.types b/tests/baselines/reference/firstMatchRegExpMatchArray.types new file mode 100644 index 0000000000000..4a30374af15ad --- /dev/null +++ b/tests/baselines/reference/firstMatchRegExpMatchArray.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/firstMatchRegExpMatchArray.ts === +const match = ''.match(/ /) +>match : RegExpMatchArray | null +>''.match(/ /) : RegExpMatchArray | null +>''.match : (regexp: string | RegExp) => RegExpMatchArray | null +>'' : "" +>match : (regexp: string | RegExp) => RegExpMatchArray | null +>/ / : RegExp + +if (match !== null) { +>match !== null : boolean +>match : RegExpMatchArray | null +>null : null + + const foo: string = match[0] +>foo : string +>match[0] : string +>match : RegExpMatchArray +>0 : 0 + + const bar: string = match[1] +>bar : string +>match[1] : string | undefined +>match : RegExpMatchArray +>1 : 1 +} + diff --git a/tests/baselines/reference/flatArrayNoExcessiveStackDepth.types b/tests/baselines/reference/flatArrayNoExcessiveStackDepth.types index 51bde63a33b80..ddf44fe2ef378 100644 --- a/tests/baselines/reference/flatArrayNoExcessiveStackDepth.types +++ b/tests/baselines/reference/flatArrayNoExcessiveStackDepth.types @@ -36,19 +36,19 @@ const repro_43249 = (value: unknown) => { >"No" : "No" } const match = value.match(/anything/) || []; ->match : RegExpMatchArray ->value.match(/anything/) || [] : RegExpMatchArray +>match : [] | RegExpMatchArray +>value.match(/anything/) || [] : RegExpMatchArray | [] >value.match(/anything/) : RegExpMatchArray | null >value.match : { (regexp: string | RegExp): RegExpMatchArray | null; (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; } >value : string >match : { (regexp: string | RegExp): RegExpMatchArray | null; (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; } >/anything/ : RegExp ->[] : never[] +>[] : [] const [, extracted] = match; > : undefined >extracted : string ->match : RegExpMatchArray +>match : [] | RegExpMatchArray }; diff --git a/tests/baselines/reference/initializedDestructuringAssignmentTypes.types b/tests/baselines/reference/initializedDestructuringAssignmentTypes.types index 333fc5d92ccd8..dae67ba90746c 100644 --- a/tests/baselines/reference/initializedDestructuringAssignmentTypes.types +++ b/tests/baselines/reference/initializedDestructuringAssignmentTypes.types @@ -3,13 +3,13 @@ const [, a = ''] = ''.match('') || []; > : undefined >a : string >'' : "" ->''.match('') || [] : RegExpMatchArray +>''.match('') || [] : RegExpMatchArray | [] >''.match('') : RegExpMatchArray >''.match : (regexp: string | RegExp) => RegExpMatchArray >'' : "" >match : (regexp: string | RegExp) => RegExpMatchArray >'' : "" ->[] : undefined[] +>[] : [] a.toFixed() >a.toFixed() : any diff --git a/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt b/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt index c28ebfd466cfe..5fb49e0dd99b6 100644 --- a/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt +++ b/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt @@ -7,5 +7,5 @@ tests/cases/compiler/mappedTypeWithAsClauseAndLateBoundProperty.ts(3,1): error T tgt2 = src2; // Should error ~~~~ !!! error TS2741: Property 'length' is missing in type '{ [x: number]: number; toString: () => string; toLocaleString: () => string; pop: () => number; push: (...items: number[]) => number; concat: { (...items: ConcatArray[]): number[]; (...items: (number | ConcatArray)[]): number[]; }; join: (separator?: string) => string; reverse: () => number[]; shift: () => number; slice: (start?: number, end?: number) => number[]; sort: (compareFn?: (a: number, b: number) => number) => number[]; splice: { (start: number, deleteCount?: number): number[]; (start: number, deleteCount: number, ...items: number[]): number[]; }; unshift: (...items: number[]) => number; indexOf: (searchElement: number, fromIndex?: number) => number; lastIndexOf: (searchElement: number, fromIndex?: number) => number; every: { (predicate: (value: number, index: number, array: number[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean; }; some: (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any) => boolean; forEach: (callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any) => void; map: (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[]; filter: { (predicate: (value: number, index: number, array: number[]) => value is S, thisArg?: any): S[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]; }; reduce: { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }; reduceRight: { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }; find: { (predicate: (this: void, value: number, index: number, obj: number[]) => value is S, thisArg?: any): S; (predicate: (value: number, index: number, obj: number[]) => unknown, thisArg?: any): number; }; findIndex: (predicate: (value: number, index: number, obj: number[]) => unknown, thisArg?: any) => number; fill: (value: number, start?: number, end?: number) => number[]; copyWithin: (target: number, start: number, end?: number) => number[]; entries: () => IterableIterator<[number, number]>; keys: () => IterableIterator; values: () => IterableIterator; includes: (searchElement: number, fromIndex?: number) => boolean; flatMap: (callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]; flat: (this: A, depth?: D) => FlatArray[]; [iterator]: () => IterableIterator; [unscopables]: () => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; }' but required in type 'number[]'. -!!! related TS2728 /.ts/lib.es5.d.ts:1295:5: 'length' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1299:5: 'length' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt b/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt index 3536907edc09f..3a07bb2f5d9b6 100644 --- a/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt +++ b/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt @@ -24,7 +24,7 @@ tests/cases/conformance/types/any/narrowExceptionVariableInCatchClause.ts(16,17) err.massage; // ERROR: Property 'massage' does not exist on type 'Error' ~~~~~~~ !!! error TS2551: Property 'massage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1045:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1049:5: 'message' is declared here. } else { diff --git a/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt b/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt index 7d0b386c63178..2206d1c9b214b 100644 --- a/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt +++ b/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt @@ -22,7 +22,7 @@ tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts(22,7): error TS x.mesage; ~~~~~~ !!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1045:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1049:5: 'message' is declared here. } if (x instanceof Date) { diff --git a/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt b/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt index 2edd0147a736e..109738a3f4bc8 100644 --- a/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt +++ b/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/types/any/narrowFromAnyWithTypePredicate.ts(33,7): error x.mesage; ~~~~~~ !!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1045:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1049:5: 'message' is declared here. } if (isDate(x)) { diff --git a/tests/baselines/reference/narrowingWithNonNullExpression.symbols b/tests/baselines/reference/narrowingWithNonNullExpression.symbols index ab95237830217..b60abdddbe61f 100644 --- a/tests/baselines/reference/narrowingWithNonNullExpression.symbols +++ b/tests/baselines/reference/narrowingWithNonNullExpression.symbols @@ -7,8 +7,11 @@ const m = ''.match(''); m! && m[0]; >m : Symbol(m, Decl(narrowingWithNonNullExpression.ts, 0, 5)) >m : Symbol(m, Decl(narrowingWithNonNullExpression.ts, 0, 5)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) m?.[0]! && m[0]; >m : Symbol(m, Decl(narrowingWithNonNullExpression.ts, 0, 5)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) >m : Symbol(m, Decl(narrowingWithNonNullExpression.ts, 0, 5)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/objectFreezeLiteralsDontWiden.symbols b/tests/baselines/reference/objectFreezeLiteralsDontWiden.symbols index 25795a61ae5fa..6eb5b43a26e59 100644 --- a/tests/baselines/reference/objectFreezeLiteralsDontWiden.symbols +++ b/tests/baselines/reference/objectFreezeLiteralsDontWiden.symbols @@ -1,9 +1,9 @@ === tests/cases/compiler/objectFreezeLiteralsDontWiden.ts === const PUPPETEER_REVISIONS = Object.freeze({ >PUPPETEER_REVISIONS : Symbol(PUPPETEER_REVISIONS, Decl(objectFreezeLiteralsDontWiden.ts, 0, 5)) ->Object.freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Object.freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) chromium: '1011831', >chromium : Symbol(chromium, Decl(objectFreezeLiteralsDontWiden.ts, 0, 43)) diff --git a/tests/baselines/reference/objectFreezeLiteralsDontWiden.types b/tests/baselines/reference/objectFreezeLiteralsDontWiden.types index 164d126cebafa..a93f6d75e0d9c 100644 --- a/tests/baselines/reference/objectFreezeLiteralsDontWiden.types +++ b/tests/baselines/reference/objectFreezeLiteralsDontWiden.types @@ -2,9 +2,9 @@ const PUPPETEER_REVISIONS = Object.freeze({ >PUPPETEER_REVISIONS : Readonly<{ chromium: "1011831"; firefox: "latest"; }> >Object.freeze({ chromium: '1011831', firefox: 'latest',}) : Readonly<{ chromium: "1011831"; firefox: "latest"; }> ->Object.freeze : { (a: T[]): readonly T[]; (f: T): T; (o: T): Readonly; (o: T): Readonly; } +>Object.freeze : { (f: T): T; (o: T): Readonly; (o: T): Readonly; } >Object : ObjectConstructor ->freeze : { (a: T[]): readonly T[]; (f: T): T; (o: T): Readonly; (o: T): Readonly; } +>freeze : { (f: T): T; (o: T): Readonly; (o: T): Readonly; } >{ chromium: '1011831', firefox: 'latest',} : { chromium: "1011831"; firefox: "latest"; } chromium: '1011831', diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity1.errors.txt b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity1.errors.txt index 043430a30bd37..252a08e5c3874 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity1.errors.txt +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity1.errors.txt @@ -7,6 +7,6 @@ tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpre /notregexp/a.foo(); ~~~~~~~~~ !!! error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'? -!!! related TS2728 /.ts/lib.es5.d.ts:1041:13: 'RegExp' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1045:13: 'RegExp' is declared here. ~ !!! error TS2304: Cannot find name 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity2.errors.txt b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity2.errors.txt index 076689e07cdca..3eb2b9824267c 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity2.errors.txt +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity2.errors.txt @@ -6,6 +6,6 @@ tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpre (1) /notregexp/a.foo(); ~~~~~~~~~ !!! error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'? -!!! related TS2728 /.ts/lib.es5.d.ts:1041:13: 'RegExp' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1045:13: 'RegExp' is declared here. ~ !!! error TS2304: Cannot find name 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt b/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt index ce9fc43e2de7c..d89e7dbdbf68f 100644 --- a/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt +++ b/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt @@ -19,7 +19,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS $ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } //CHECK#2 @@ -28,7 +28,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS $ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } diff --git a/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt b/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt index d746cc3dd0088..1b259eccc99b7 100644 --- a/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt +++ b/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.3_A1.1_T2.ts(17,3): error TS $ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt b/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt index 9fb072acf812a..3e7acb4d3f164 100644 --- a/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt +++ b/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt @@ -50,70 +50,70 @@ tests/cases/conformance/parser/ecmascript5/parserS7.6_A4.2_T1.ts(142,3): error T $ERROR('#А'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0411 = 1; if (Б !== 1) { $ERROR('#Б'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0412 = 1; if (В !== 1) { $ERROR('#В'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0413 = 1; if (Г !== 1) { $ERROR('#Г'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0414 = 1; if (Д !== 1) { $ERROR('#Д'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0415 = 1; if (Е !== 1) { $ERROR('#Е'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0416 = 1; if (Ж !== 1) { $ERROR('#Ж'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0417 = 1; if (З !== 1) { $ERROR('#З'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0418 = 1; if (И !== 1) { $ERROR('#И'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0419 = 1; if (Й !== 1) { $ERROR('#Й'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u041A = 1; if (К !== 1) { diff --git a/tests/baselines/reference/parserUnicode1.errors.txt b/tests/baselines/reference/parserUnicode1.errors.txt index 3534eddcffa3f..d2f7148f6f271 100644 --- a/tests/baselines/reference/parserUnicode1.errors.txt +++ b/tests/baselines/reference/parserUnicode1.errors.txt @@ -11,13 +11,13 @@ tests/cases/conformance/parser/ecmascript5/parserUnicode1.ts(10,5): error TS2552 $ERROR('#6.1: var \\u0078x = 1; xx === 6. Actual: ' + (xx)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } } catch (e) { $ERROR('#6.2: var \\u0078x = 1; xx === 6. Actual: ' + (xx)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/parserharness.symbols b/tests/baselines/reference/parserharness.symbols index 92953908f7344..62604cadf5a19 100644 --- a/tests/baselines/reference/parserharness.symbols +++ b/tests/baselines/reference/parserharness.symbols @@ -3809,6 +3809,7 @@ module Harness { >path.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) >path : Symbol(path, Decl(parserharness.ts, 1285, 36)) >match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) var code = readFile(path); >code : Symbol(code, Decl(parserharness.ts, 1288, 15)) @@ -3946,6 +3947,7 @@ module Harness { >lastUnit : Symbol(lastUnit, Decl(parserharness.ts, 1326, 15)) >name : Symbol(TestCaseParser.TestUnitData.name, Decl(parserharness.ts, 1422, 28)) >match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) var dependencies = units.slice(0, units.length - 1); >dependencies : Symbol(dependencies, Decl(parserharness.ts, 1329, 15)) @@ -5698,6 +5700,7 @@ module Harness { >path.match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) >path : Symbol(path, Decl(parserharness.ts, 1869, 38)) >match : Symbol(String.match, Decl(lib.es5.d.ts, --, --)) +>0 : Symbol(RegExpMatchArray[0], Decl(lib.es5.d.ts, --, --)) >callback : Symbol(callback, Decl(parserharness.ts, 1869, 51)) } diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index 9782d2b562c2c..c9862aec4ec6c 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -447,7 +447,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2769: No overload m !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1531:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1535:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations.ts:5:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 812c3eb3d560a..17ac4d4aa3c72 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -351,7 +351,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1531:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1535:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index a6b8b6e5c58ee..835c3fcb71bcf 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -398,7 +398,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1531:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1535:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations3.ts:7:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok @@ -445,5 +445,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1531:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1535:5: 'catch' is declared here. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 582d4e157f94d..0af9576082efa 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is Array = function (n:number, s:string) {return n;}; ~~~~~ !!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'. -!!! related TS2728 /.ts/lib.es5.d.ts:1482:5: 'isArray' is declared here. \ No newline at end of file +!!! related TS2728 /.ts/lib.es5.d.ts:1486:5: 'isArray' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt b/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt index 20bf8b550e8ec..535cc4b2f970f 100644 --- a/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt +++ b/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt @@ -19,7 +19,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error $ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } //CHECK#2 @@ -28,7 +28,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error $ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } diff --git a/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt b/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt index 4336b9a2d88af..40c4e573c779d 100644 --- a/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt +++ b/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.3_A1.1_T2.ts(17,3): error $ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt b/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt index 3b1f35e564690..ba258b4f255c3 100644 --- a/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt +++ b/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt @@ -50,70 +50,70 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.6_A4.2_T1.ts(142,3): error $ERROR('#А'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0411 = 1; if (Б !== 1) { $ERROR('#Б'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0412 = 1; if (В !== 1) { $ERROR('#В'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0413 = 1; if (Г !== 1) { $ERROR('#Г'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0414 = 1; if (Д !== 1) { $ERROR('#Д'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0415 = 1; if (Е !== 1) { $ERROR('#Е'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0416 = 1; if (Ж !== 1) { $ERROR('#Ж'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0417 = 1; if (З !== 1) { $ERROR('#З'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0418 = 1; if (И !== 1) { $ERROR('#И'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u0419 = 1; if (Й !== 1) { $ERROR('#Й'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1055:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1059:13: 'Error' is declared here. } var \u041A = 1; if (К !== 1) { diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js index 83e659775604a..c31b76ea3934c 100644 --- a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.js @@ -48,7 +48,7 @@ class C implements String { indexOf(searchString: string, position?: number): number { return null; } lastIndexOf(searchString: string, position?: number): number { return null; } localeCompare(that: string): number { return null; } - match(regexp: any): string[] { return null; } + match(regexp: any): RegExpMatchArray { return null; } replace(searchValue: any, replaceValue: any): string { return null; } search(regexp: any): number { return null; } slice(start?: number, end?: number): string { return null; } @@ -64,7 +64,7 @@ class C implements String { valueOf(): string { return null; } [index: number]: string; } - + // BUG 831846 function f10(x: 'a'); function f10(x: C); @@ -98,7 +98,8 @@ function f15(x: any) { } function f16(x: 'a'); function f16(x: U); -function f16(x: any) { } +function f16(x: any) { } + //// [stringLiteralTypeIsSubtypeOfString.js] // string literal types are subtypes of string, any diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols index cf735eb7042aa..08448089a60c8 100644 --- a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols @@ -148,12 +148,13 @@ class C implements String { >localeCompare : Symbol(C.localeCompare, Decl(stringLiteralTypeIsSubtypeOfString.ts, 47, 81)) >that : Symbol(that, Decl(stringLiteralTypeIsSubtypeOfString.ts, 48, 18)) - match(regexp: any): string[] { return null; } + match(regexp: any): RegExpMatchArray { return null; } >match : Symbol(C.match, Decl(stringLiteralTypeIsSubtypeOfString.ts, 48, 56)) >regexp : Symbol(regexp, Decl(stringLiteralTypeIsSubtypeOfString.ts, 49, 10)) +>RegExpMatchArray : Symbol(RegExpMatchArray, Decl(lib.es5.d.ts, --, --)) replace(searchValue: any, replaceValue: any): string { return null; } ->replace : Symbol(C.replace, Decl(stringLiteralTypeIsSubtypeOfString.ts, 49, 49)) +>replace : Symbol(C.replace, Decl(stringLiteralTypeIsSubtypeOfString.ts, 49, 57)) >searchValue : Symbol(searchValue, Decl(stringLiteralTypeIsSubtypeOfString.ts, 50, 12)) >replaceValue : Symbol(replaceValue, Decl(stringLiteralTypeIsSubtypeOfString.ts, 50, 29)) @@ -205,7 +206,7 @@ class C implements String { [index: number]: string; >index : Symbol(index, Decl(stringLiteralTypeIsSubtypeOfString.ts, 63, 5)) } - + // BUG 831846 function f10(x: 'a'); >f10 : Symbol(f10, Decl(stringLiteralTypeIsSubtypeOfString.ts, 64, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 67, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 68, 19)) diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types index f5216a5b9ad3a..13d3407875460 100644 --- a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types @@ -151,8 +151,8 @@ class C implements String { >that : string >null : null - match(regexp: any): string[] { return null; } ->match : (regexp: any) => string[] + match(regexp: any): RegExpMatchArray { return null; } +>match : (regexp: any) => RegExpMatchArray >regexp : any >null : null @@ -221,7 +221,7 @@ class C implements String { [index: number]: string; >index : number } - + // BUG 831846 function f10(x: 'a'); >f10 : { (x: 'a'): any; (x: C): any; } diff --git a/tests/cases/compiler/firstMatchRegExpMatchArray.ts b/tests/cases/compiler/firstMatchRegExpMatchArray.ts new file mode 100644 index 0000000000000..265d564fc51f7 --- /dev/null +++ b/tests/cases/compiler/firstMatchRegExpMatchArray.ts @@ -0,0 +1,9 @@ +// @strict: true +// @noUncheckedIndexedAccess: true + +const match = ''.match(/ /) + +if (match !== null) { + const foo: string = match[0] + const bar: string = match[1] +} diff --git a/tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts b/tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts index 16308f902513b..9c971ea5614e1 100644 --- a/tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts +++ b/tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts @@ -11,8 +11,8 @@ interface NotString { indexOf(searchString: string, position?: number): number; lastIndexOf(searchString: string, position?: number): number; localeCompare(that: string): number; - match(regexp: string): string[]; - match(regexp: RegExp): string[]; + match(regexp: string): RegExpMatchArray; + match(regexp: RegExp): RegExpMatchArray; replace(searchValue: string, replaceValue: string): string; replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; replace(searchValue: RegExp, replaceValue: string): string; @@ -38,11 +38,11 @@ var x = ''; var a: String; var b: NotString; -a = x; -a = b; +a = x; +a = b; -b = a; -b = x; +b = a; +b = x; x = a; // expected error x = b; // expected error diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts index c7e9c0fc8e971..01e0c7ba067a6 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts @@ -47,7 +47,7 @@ class C implements String { indexOf(searchString: string, position?: number): number { return null; } lastIndexOf(searchString: string, position?: number): number { return null; } localeCompare(that: string): number { return null; } - match(regexp: any): string[] { return null; } + match(regexp: any): RegExpMatchArray { return null; } replace(searchValue: any, replaceValue: any): string { return null; } search(regexp: any): number { return null; } slice(start?: number, end?: number): string { return null; } @@ -63,7 +63,7 @@ class C implements String { valueOf(): string { return null; } [index: number]: string; } - + // BUG 831846 function f10(x: 'a'); function f10(x: C); @@ -97,4 +97,4 @@ function f15(x: any) { } function f16(x: 'a'); function f16(x: U); -function f16(x: any) { } \ No newline at end of file +function f16(x: any) { }