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

Add types for String.{matchAll,replaceAll} with a well known symbol #61449

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/es2020.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ interface RegExp {
*/
[Symbol.matchAll](str: string): RegExpStringIterator<RegExpMatchArray>;
}

interface String {
/**
* Matches a string or an object that supports being matched against, and
* returns an iterable of matches containing the results of that search.
* @param regexp An object that supports being matched against.
*/
matchAll(matcher: { [Symbol.matchAll](str: string): RegExpStringIterator<RegExpMatchArray>; }): RegExpStringIterator<RegExpExecArray>;
}
1 change: 1 addition & 0 deletions src/lib/es2021.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference lib="es2020" />
/// <reference lib="es2021.promise" />
/// <reference lib="es2021.string" />
/// <reference lib="es2021.symbol.wellknown" />
/// <reference lib="es2021.weakref" />
/// <reference lib="es2021.intl" />
6 changes: 4 additions & 2 deletions src/lib/es2021.string.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/// <reference lib="es2021.symbol.wellknown" />

interface String {
/**
* Replace all instances of a substring in a string, using a regular expression or search string.
* @param searchValue A string to search for.
* @param searchValue An object that supports searching for and replacing matches within a string.
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
*/
replaceAll(searchValue: string | RegExp, replaceValue: string): string;

/**
* Replace all instances of a substring in a string, using a regular expression or search string.
* @param searchValue A string to search for.
* @param searchValue An object that supports searching for and replacing matches within a string.
* @param replacer A function that returns the replacement text.
*/
replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
Expand Down
17 changes: 17 additions & 0 deletions src/lib/es2021.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference lib="es2015.symbol.wellknown" />

interface String {
/**
* Replace all instances of a substring in a string, using an object that supports replacement within a string.
* @param searchValue A string to search for.
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
*/
replaceAll(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;

/**
* Replace all instances of a substring in a string, using an object that supports replacement within a string.
* @param searchValue A string to search for.
* @param replacer A function that returns the replacement text.
*/
replaceAll(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string;
}
Loading