Skip to content

Commit 36d187d

Browse files
committed
Add types for String.{matchAll,replaceAll} with a well known symbol
1 parent 7205eda commit 36d187d

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/lib/es2020.symbol.wellknown.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ interface RegExp {
2121
*/
2222
[Symbol.matchAll](str: string): RegExpStringIterator<RegExpMatchArray>;
2323
}
24+
25+
interface String {
26+
/**
27+
* Matches a string or an object that supports being matched against, and
28+
* returns an iterable of matches containing the results of that search.
29+
* @param regexp An object that supports being matched against.
30+
*/
31+
matchAll(matcher: { [Symbol.matchAll](str: string): RegExpStringIterator<RegExpMatchArray>; }): RegExpStringIterator<RegExpExecArray>;
32+
}

src/lib/es2021.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference lib="es2020" />
22
/// <reference lib="es2021.promise" />
33
/// <reference lib="es2021.string" />
4+
/// <reference lib="es2021.symbol.wellknown" />
45
/// <reference lib="es2021.weakref" />
56
/// <reference lib="es2021.intl" />

src/lib/es2021.string.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
/// <reference lib="es2021.symbol.wellknown" />
2+
13
interface String {
24
/**
35
* Replace all instances of a substring in a string, using a regular expression or search string.
4-
* @param searchValue A string to search for.
6+
* @param searchValue An object that supports searching for and replacing matches within a string.
57
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
68
*/
79
replaceAll(searchValue: string | RegExp, replaceValue: string): string;
810

911
/**
1012
* Replace all instances of a substring in a string, using a regular expression or search string.
11-
* @param searchValue A string to search for.
13+
* @param searchValue An object that supports searching for and replacing matches within a string.
1214
* @param replacer A function that returns the replacement text.
1315
*/
1416
replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;

src/lib/es2021.symbol.wellknown.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference lib="es2015.symbol.wellknown" />
2+
3+
interface String {
4+
/**
5+
* Replace all instances of a substring in a string, using an object that supports replacement within a string.
6+
* @param searchValue A string to search for.
7+
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
8+
*/
9+
replaceAll(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;
10+
11+
/**
12+
* Replace all instances of a substring in a string, using an object that supports replacement within a string.
13+
* @param searchValue A string to search for.
14+
* @param replacer A function that returns the replacement text.
15+
*/
16+
replaceAll(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string;
17+
}

0 commit comments

Comments
 (0)