Skip to content

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

Closed
segevfiner wants to merge 2 commits intomicrosoft:mainfrom
segevfiner:regexp-symbol-replace-all-match-all
Closed

Add types for String.{matchAll,replaceAll} with a well known symbol#61449
segevfiner wants to merge 2 commits intomicrosoft:mainfrom
segevfiner:regexp-symbol-replace-all-match-all

Conversation

@segevfiner
Copy link
Copy Markdown

Fixes #61448

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Mar 19, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 19, 2025
@segevfiner segevfiner force-pushed the regexp-symbol-replace-all-match-all branch from 72fb2ed to 36d187d Compare April 2, 2025 14:54
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 2, 2025
* 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>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String.prototype.matchAll, when on the [Symbol.matchAll] codepath, just forwards the call to the passed matcher and returns whatever it returns. There's no limitations on the type of the return and no coercion done. Should this then be generic in the return type?

matchAll<T>(matcher: { [Symbol.matchAll](str: string): T; }): T;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this apply to all the other [Symbol] RegExp symbols. I don't think it was done for them, it would also make it inconvenient to call, as in the common case, its supposed to return RegExpStringIterator<RegExpMatchArray>, returning something else is technically unexpected, and kinda violates what the symbol is meant to do.

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

5 participants