Skip to content

Commit 12f7799

Browse files
authored
Join some overloads of string methods to union parameters
Fixes the string methods which accept either a string or RegExp as pattern. Also, some help texts were fixed to represent the actual behavior as per spec. See microsoft#5766
1 parent aeeff28 commit 12f7799

File tree

1 file changed

+11
-44
lines changed

1 file changed

+11
-44
lines changed

lib/lib.d.ts

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -349,55 +349,29 @@ interface String {
349349

350350
/**
351351
* Matches a string with a regular expression, and returns an array containing the results of that search.
352-
* @param regexp A variable name or string literal containing the regular expression pattern and flags.
352+
* @param regexp A string containing the regular expression pattern or a regular expression object.
353353
*/
354-
match(regexp: string): RegExpMatchArray | null;
354+
match(regexp: RegExp | string): RegExpMatchArray | null;
355355

356356
/**
357-
* Matches a string with a regular expression, and returns an array containing the results of that search.
358-
* @param regexp A regular expression object that contains the regular expression pattern and applicable flags.
359-
*/
360-
match(regexp: RegExp): RegExpMatchArray | null;
361-
362-
/**
363-
* Replaces text in a string, using a regular expression or search string.
364-
* @param searchValue A string that represents the regular expression.
357+
* Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences.
358+
* @param searchValue A literal search string or a regular expression object.
365359
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
366360
*/
367-
replace(searchValue: string, replaceValue: string): string;
361+
replace(searchValue: RegExp | string, replaceValue: string): string;
368362

369363
/**
370-
* Replaces text in a string, using a regular expression or search string.
364+
* Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences.
371365
* @param searchValue A string that represents the regular expression.
372366
* @param replacer A function that returns the replacement text.
373367
*/
374-
replace(searchValue: string, replacer: (substring: string, ...args: any[]) => string): string;
375-
376-
/**
377-
* Replaces text in a string, using a regular expression or search string.
378-
* @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags.
379-
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
380-
*/
381-
replace(searchValue: RegExp, replaceValue: string): string;
382-
383-
/**
384-
* Replaces text in a string, using a regular expression or search string.
385-
* @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags
386-
* @param replacer A function that returns the replacement text.
387-
*/
388-
replace(searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string;
389-
390-
/**
391-
* Finds the first substring match in a regular expression search.
392-
* @param regexp The regular expression pattern and applicable flags.
393-
*/
394-
search(regexp: string): number;
368+
replace(searchValue: RegExp | string, replacer: (substring: string, ...args: any[]) => string): string;
395369

396370
/**
397371
* Finds the first substring match in a regular expression search.
398-
* @param regexp The regular expression pattern and applicable flags.
372+
* @param regexp The regular expression pattern or object.
399373
*/
400-
search(regexp: RegExp): number;
374+
search(regexp: RegExp | string): number;
401375

402376
/**
403377
* Returns a section of a string.
@@ -409,17 +383,10 @@ interface String {
409383

410384
/**
411385
* Split a string into substrings using the specified separator and return them as an array.
412-
* @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.
413-
* @param limit A value used to limit the number of elements returned in the array.
414-
*/
415-
split(separator: string, limit?: number): string[];
416-
417-
/**
418-
* Split a string into substrings using the specified separator and return them as an array.
419-
* @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.
386+
* @param separator A literal string or a regular expression object that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
420387
* @param limit A value used to limit the number of elements returned in the array.
421388
*/
422-
split(separator: RegExp, limit?: number): string[];
389+
split(separator: RegExp | string, limit?: number): string[];
423390

424391
/**
425392
* Returns the substring at the specified location within a String object.

0 commit comments

Comments
 (0)