Skip to content

Commit ea57fbc

Browse files
authored
Merge pull request microsoft#14639 from falsandtru/lib.d.ts/overload
Convert overloads to unions
2 parents 84d5d44 + d86976a commit ea57fbc

13 files changed

+51
-84
lines changed

src/lib/es5.d.ts

+7-40
Original file line numberDiff line numberDiff line change
@@ -325,53 +325,27 @@ interface String {
325325
* Matches a string with a regular expression, and returns an array containing the results of that search.
326326
* @param regexp A variable name or string literal containing the regular expression pattern and flags.
327327
*/
328-
match(regexp: string): RegExpMatchArray | null;
329-
330-
/**
331-
* Matches a string with a regular expression, and returns an array containing the results of that search.
332-
* @param regexp A regular expression object that contains the regular expression pattern and applicable flags.
333-
*/
334-
match(regexp: RegExp): RegExpMatchArray | null;
328+
match(regexp: string | RegExp): RegExpMatchArray | null;
335329

336330
/**
337331
* Replaces text in a string, using a regular expression or search string.
338332
* @param searchValue A string to search for.
339333
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
340334
*/
341-
replace(searchValue: string, replaceValue: string): string;
335+
replace(searchValue: string | RegExp, replaceValue: string): string;
342336

343337
/**
344338
* Replaces text in a string, using a regular expression or search string.
345339
* @param searchValue A string to search for.
346340
* @param replacer A function that returns the replacement text.
347341
*/
348-
replace(searchValue: string, replacer: (substring: string, ...args: any[]) => string): string;
349-
350-
/**
351-
* Replaces text in a string, using a regular expression or search string.
352-
* @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags.
353-
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
354-
*/
355-
replace(searchValue: RegExp, replaceValue: string): string;
356-
357-
/**
358-
* Replaces text in a string, using a regular expression or search string.
359-
* @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags
360-
* @param replacer A function that returns the replacement text.
361-
*/
362-
replace(searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string;
363-
364-
/**
365-
* Finds the first substring match in a regular expression search.
366-
* @param regexp The regular expression pattern and applicable flags.
367-
*/
368-
search(regexp: string): number;
342+
replace(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
369343

370344
/**
371345
* Finds the first substring match in a regular expression search.
372346
* @param regexp The regular expression pattern and applicable flags.
373347
*/
374-
search(regexp: RegExp): number;
348+
search(regexp: string | RegExp): number;
375349

376350
/**
377351
* Returns a section of a string.
@@ -386,14 +360,7 @@ interface String {
386360
* @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
387361
* @param limit A value used to limit the number of elements returned in the array.
388362
*/
389-
split(separator: string, limit?: number): string[];
390-
391-
/**
392-
* Split a string into substrings using the specified separator and return them as an array.
393-
* @param separator A Regular Express that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
394-
* @param limit A value used to limit the number of elements returned in the array.
395-
*/
396-
split(separator: RegExp, limit?: number): string[];
363+
split(separator: string | RegExp, limit?: number): string[];
397364

398365
/**
399366
* Returns the substring at the specified location within a String object.
@@ -861,9 +828,9 @@ interface RegExp {
861828
}
862829

863830
interface RegExpConstructor {
864-
new (pattern: RegExp): RegExp;
831+
new (pattern: RegExp | string): RegExp;
865832
new (pattern: string, flags?: string): RegExp;
866-
(pattern: RegExp): RegExp;
833+
(pattern: RegExp | string): RegExp;
867834
(pattern: string, flags?: string): RegExp;
868835
readonly prototype: RegExp;
869836

tests/baselines/reference/bestChoiceType.symbols

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
(''.match(/ /) || []).map(s => s.toLowerCase());
66
>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
7-
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
8-
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
7+
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --))
8+
>match : Symbol(String.match, Decl(lib.d.ts, --, --))
99
>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
1010
>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26))
1111
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
@@ -19,8 +19,8 @@ function f1() {
1919

2020
let x = ''.match(/ /);
2121
>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7))
22-
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
23-
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
22+
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --))
23+
>match : Symbol(String.match, Decl(lib.d.ts, --, --))
2424

2525
let y = x || [];
2626
>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7))
@@ -42,8 +42,8 @@ function f2() {
4242

4343
let x = ''.match(/ /);
4444
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
45-
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
46-
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
45+
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --))
46+
>match : Symbol(String.match, Decl(lib.d.ts, --, --))
4747

4848
let y = x ? x : [];
4949
>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7))

tests/baselines/reference/bestChoiceType.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
>(''.match(/ /) || []) : RegExpMatchArray
99
>''.match(/ /) || [] : RegExpMatchArray
1010
>''.match(/ /) : RegExpMatchArray | null
11-
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
11+
>''.match : (regexp: string | RegExp) => RegExpMatchArray | null
1212
>'' : ""
13-
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
13+
>match : (regexp: string | RegExp) => RegExpMatchArray | null
1414
>/ / : RegExp
1515
>[] : never[]
1616
>map : { <U>(this: [string, string, string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U): [U, U, U, U, U]; <U>(this: [string, string, string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U, thisArg: undefined): [U, U, U, U, U]; <Z, U>(this: [string, string, string, string, string], callbackfn: (this: Z, value: string, index: number, array: string[]) => U, thisArg: Z): [U, U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U): [U, U, U, U]; <U>(this: [string, string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U, thisArg: undefined): [U, U, U, U]; <Z, U>(this: [string, string, string, string], callbackfn: (this: Z, value: string, index: number, array: string[]) => U, thisArg: Z): [U, U, U, U]; <U>(this: [string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U): [U, U, U]; <U>(this: [string, string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U, thisArg: undefined): [U, U, U]; <Z, U>(this: [string, string, string], callbackfn: (this: Z, value: string, index: number, array: string[]) => U, thisArg: Z): [U, U, U]; <U>(this: [string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U): [U, U]; <U>(this: [string, string], callbackfn: (this: undefined, value: string, index: number, array: string[]) => U, thisArg: undefined): [U, U]; <Z, U>(this: [string, string], callbackfn: (this: Z, value: string, index: number, array: string[]) => U, thisArg: Z): [U, U]; <U>(callbackfn: (this: undefined, value: string, index: number, array: string[]) => U): U[]; <U>(callbackfn: (this: undefined, value: string, index: number, array: string[]) => U, thisArg: undefined): U[]; <Z, U>(callbackfn: (this: Z, value: string, index: number, array: string[]) => U, thisArg: Z): U[]; }
@@ -29,9 +29,9 @@ function f1() {
2929
let x = ''.match(/ /);
3030
>x : RegExpMatchArray | null
3131
>''.match(/ /) : RegExpMatchArray | null
32-
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
32+
>''.match : (regexp: string | RegExp) => RegExpMatchArray | null
3333
>'' : ""
34-
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
34+
>match : (regexp: string | RegExp) => RegExpMatchArray | null
3535
>/ / : RegExp
3636

3737
let y = x || [];
@@ -60,9 +60,9 @@ function f2() {
6060
let x = ''.match(/ /);
6161
>x : RegExpMatchArray | null
6262
>''.match(/ /) : RegExpMatchArray | null
63-
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
63+
>''.match : (regexp: string | RegExp) => RegExpMatchArray | null
6464
>'' : ""
65-
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
65+
>match : (regexp: string | RegExp) => RegExpMatchArray | null
6666
>/ / : RegExp
6767

6868
let y = x ? x : [];

tests/baselines/reference/controlFlowPropertyDeclarations.symbols

+4-4
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ export class HTMLtoJSX {
220220
// wrapping newlines and sequences of two or more spaces in variables.
221221
text = text
222222
>text : Symbol(text, Decl(controlFlowPropertyDeclarations.ts, 113, 7))
223-
>text .replace(/\r/g, '') .replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
224-
>text .replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
223+
>text .replace(/\r/g, '') .replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
224+
>text .replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
225225
>text : Symbol(text, Decl(controlFlowPropertyDeclarations.ts, 113, 7))
226226

227227
.replace(/\r/g, '')
228-
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
228+
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
229229

230230
.replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) {
231-
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
231+
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
232232
>whitespace : Symbol(whitespace, Decl(controlFlowPropertyDeclarations.ts, 121, 50))
233233

234234
return '{' + JSON.stringify(whitespace) + '}';

tests/baselines/reference/controlFlowPropertyDeclarations.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,18 @@ export class HTMLtoJSX {
295295
>text = text .replace(/\r/g, '') .replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; }) : string
296296
>text : string
297297
>text .replace(/\r/g, '') .replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; }) : string
298-
>text .replace(/\r/g, '') .replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
298+
>text .replace(/\r/g, '') .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
299299
>text .replace(/\r/g, '') : string
300-
>text .replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
300+
>text .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
301301
>text : string
302302

303303
.replace(/\r/g, '')
304-
>replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
304+
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
305305
>/\r/g : RegExp
306306
>'' : ""
307307

308308
.replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) {
309-
>replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
309+
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
310310
>/( {2,}|\n|\t|\{|\})/g : RegExp
311311
>function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; } : (whitespace: string) => string
312312
>whitespace : string

tests/baselines/reference/noImplicitAnyInContextuallyTypesFunctionParamter.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ regexMatchList.forEach(match => ''.replace(match, ''));
88
>regexMatchList : Symbol(regexMatchList, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 1, 3))
99
>forEach : Symbol(Array.forEach, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
1010
>match : Symbol(match, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 2, 23))
11-
>''.replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
12-
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
11+
>''.replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
12+
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
1313
>match : Symbol(match, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 2, 23))
1414

tests/baselines/reference/noImplicitAnyInContextuallyTypesFunctionParamter.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ regexMatchList.forEach(match => ''.replace(match, ''));
1414
>match => ''.replace(match, '') : (this: undefined, match: string) => string
1515
>match : string
1616
>''.replace(match, '') : string
17-
>''.replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
17+
>''.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
1818
>'' : ""
19-
>replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
19+
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
2020
>match : string
2121
>'' : ""
2222

tests/baselines/reference/overloadResolutionOverNonCTLambdas.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module Bugs {
1414

1515
var result= message.replace(/\{(\d+)\}/g, function(match, ...rest) {
1616
>result : Symbol(result, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 7))
17-
>message.replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
17+
>message.replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
1818
>message : Symbol(message, Decl(overloadResolutionOverNonCTLambdas.ts, 5, 16))
19-
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
19+
>replace : Symbol(String.replace, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
2020
>match : Symbol(match, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 55))
2121
>rest : Symbol(rest, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 61))
2222

tests/baselines/reference/overloadResolutionOverNonCTLambdas.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ module Bugs {
1515
var result= message.replace(/\{(\d+)\}/g, function(match, ...rest) {
1616
>result : string
1717
>message.replace(/\{(\d+)\}/g, function(match, ...rest) { var index= rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; }) : string
18-
>message.replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
18+
>message.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
1919
>message : string
20-
>replace : { (searchValue: string, replaceValue: string): string; (searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
20+
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
2121
>/\{(\d+)\}/g : RegExp
2222
>function(match, ...rest) { var index= rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; } : (match: string, ...rest: any[]) => any
2323
>match : string

tests/baselines/reference/parser630933.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var a = "Hello";
44

55
var b = a.match(/\/ver=([^/]+)/);
66
>b : Symbol(b, Decl(parser630933.ts, 1, 3))
7-
>a.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
7+
>a.match : Symbol(String.match, Decl(lib.d.ts, --, --))
88
>a : Symbol(a, Decl(parser630933.ts, 0, 3))
9-
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
9+
>match : Symbol(String.match, Decl(lib.d.ts, --, --))
1010

tests/baselines/reference/parser630933.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var a = "Hello";
66
var b = a.match(/\/ver=([^/]+)/);
77
>b : RegExpMatchArray
88
>a.match(/\/ver=([^/]+)/) : RegExpMatchArray
9-
>a.match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; }
9+
>a.match : (regexp: string | RegExp) => RegExpMatchArray
1010
>a : string
11-
>match : { (regexp: string): RegExpMatchArray; (regexp: RegExp): RegExpMatchArray; }
11+
>match : (regexp: string | RegExp) => RegExpMatchArray
1212
>/\/ver=([^/]+)/ : RegExp
1313

0 commit comments

Comments
 (0)