René's URL Explorer Experiment


Title: Notes about `String.replace` · Issue #54387 · microsoft/TypeScript · GitHub

Open Graph Title: Notes about `String.replace` · Issue #54387 · microsoft/TypeScript

X Title: Notes about `String.replace` · Issue #54387 · microsoft/TypeScript

Description: (Moved from rom microsoft/TypeScript-DOM-lib-generator#1562) I am using TypeScript 5.0.4. I have noticed the typing of String.replace seem oddly convoluted. From lib.es5.d.ts: interface String { replace(searchValue: string | RegExp, repl...

Open Graph Description: (Moved from rom microsoft/TypeScript-DOM-lib-generator#1562) I am using TypeScript 5.0.4. I have noticed the typing of String.replace seem oddly convoluted. From lib.es5.d.ts: interface String { re...

X Description: (Moved from rom microsoft/TypeScript-DOM-lib-generator#1562) I am using TypeScript 5.0.4. I have noticed the typing of String.replace seem oddly convoluted. From lib.es5.d.ts: interface String { re...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/54387

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Notes about `String.replace`","articleBody":"(Moved from rom https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1562)\r\n\r\nI am using TypeScript 5.0.4.\r\nI have noticed the typing of `String.replace` seem oddly convoluted.\r\n\r\nFrom `lib.es5.d.ts`:\r\n```ts\r\ninterface String {\r\n    replace(searchValue: string | RegExp, replaceValue: string): string;\r\n    replace(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;\r\n}\r\n```\r\n\r\nFrom `lib.es2015.symbol.wellknown.d.ts`:\r\n```ts\r\ninterface String {\r\n    replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;\r\n    replace(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string;\r\n}\r\n```\r\n\r\nLike the first parameter is declared as an union, I would expect the second to be the same, at least in the `lib.es5` version.\r\n\r\nNotably, this makes the following code not compile:\r\n\r\n```ts\r\n// The second argument is an union of replaceValue and replacer from lib.es5\r\nconst replacementSteps: ([RegExp, string | ((substring: string, ...args: any[]) => string)])[] = [\r\n    [/(a|b)/gi, \"a\"],\r\n    [/(c|d)/gi, match => match.toUpperCase()],\r\n];\r\n\r\nlet myString = \"abcdef\";\r\n\r\nfor (const [searchValue, replacement] of replacementSteps)\r\n    myString = myString.replace(searchValue, replacement); // TS2345 - the second parameter is considered invalid\r\n```\r\n\r\nBy adding this into my declaration, the code works:\r\n\r\n```ts\r\ndeclare interface String {\r\n    replace(searchValue: string | RegExp, replaceValue: string | ((substring: string, ...args: any[]) => string)): string;\r\n}\r\n```\r\n\r\nI cannot propose a solution other than my last hack, and of course the variants with `Symbol` would have to be taken into account. Please consider this just a note.\r\n\r\nSee also this: https://github.com/microsoft/TypeScript/issues/54223","author":{"url":"https://github.com/m-gallesio","@type":"Person","name":"m-gallesio"},"datePublished":"2023-05-25T07:31:59Z","url":"https://github.com/microsoft/TypeScript/issues/54387"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a5cb209d-699f-1716-09ca-8454b8b83da3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC502:157C65:2F1A30B:3ED7F29:6B01E242
html-safe-noncec2d938e4cdcf40627cf8cf61085c2572874862ae1d36074ed4f4a8e608a944bd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTAyOjE1N0M2NToyRjFBMzBCOjNFRDdGMjk6NkIwMUUyNDIiLCJ2aXNpdG9yX2lkIjoiMzI3NTY0OTA4MjE0NDc3Mzc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac4ebc7afb4e7f22a820baa64b3b0e3876ba2d1a0b4694042cc95dc5cb69384d04
hovercard-subject-tagissue:1725254013
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/54387/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b571659e153b57e3d56f61e0429c07772bc1864a622510ba9c06e12580515de1/microsoft/TypeScript/issues/54387
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b571659e153b57e3d56f61e0429c07772bc1864a622510ba9c06e12580515de1/microsoft/TypeScript/issues/54387
og:image:alt(Moved from rom microsoft/TypeScript-DOM-lib-generator#1562) I am using TypeScript 5.0.4. I have noticed the typing of String.replace seem oddly convoluted. From lib.es5.d.ts: interface String { re...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamem-gallesio
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/54387#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F54387
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F54387
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/54387
Reloadhttps://github.com/microsoft/TypeScript/issues/54387
Reloadhttps://github.com/microsoft/TypeScript/issues/54387
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/54387
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/54387
#64442https://github.com/microsoft/TypeScript/pull/64442
#64330https://github.com/microsoft/TypeScript/pull/64330
Notes about String.replacehttps://github.com/microsoft/TypeScript/issues/54387#top
#64442https://github.com/microsoft/TypeScript/pull/64442
#64330https://github.com/microsoft/TypeScript/pull/64330
https://github.com/RyanCavanaugh
https://github.com/copilot-swe-agent
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20lib.d.ts%22
Backloghttps://github.com/microsoft/TypeScript/milestone/29
https://github.com/m-gallesio
m-gallesiohttps://github.com/m-gallesio
on May 25, 2023https://github.com/microsoft/TypeScript/issues/54387#issue-1725254013
microsoft/TypeScript-DOM-lib-generator#1562https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1562
#54223https://github.com/microsoft/TypeScript/issues/54223
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Help Wantedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Help%20Wanted%22
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20lib.d.ts%22
on May 26, 2023https://github.com/microsoft/TypeScript/issues/54387#event-9353109359
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Backloghttps://github.com/microsoft/TypeScript/milestone/29
on May 26, 2023https://github.com/microsoft/TypeScript/issues/54387#event-9353110076
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on May 26, 2023https://github.com/microsoft/TypeScript/issues/54387#issuecomment-1564704374
https://github.com/graphemecluster
graphemecluster (graphemecluster)https://github.com/graphemecluster
on Sep 9, 2023https://github.com/microsoft/TypeScript/issues/54387#issuecomment-1712437149
#50452https://github.com/microsoft/TypeScript/pull/50452
https://github.com/jwasnoggin
jwasnogginhttps://github.com/jwasnoggin
on Jan 19, 2024https://github.com/microsoft/TypeScript/issues/54387#issuecomment-1899806758
https://github.com/electrovir
electrovir (electrovir)https://github.com/electrovir
on Oct 6, 2025https://github.com/microsoft/TypeScript/issues/54387#issuecomment-3374188716
playground linkhttps://www.typescriptlang.org/play/#code/FAYw9gdgzgLgBAWwJ4CUCmAHANgQxGgJzgF44ByMuHKOWAgSwgHM4AfOACg6gFcAjOoyYAuWjAbMANHAB0cnASZRROCEgDaAXQCUJAHxiJTbQG5gwCjIKZc+DgHoA7gAscMNADdC96cnTY8Qm0gA
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Sep 19, 2026https://github.com/microsoft/TypeScript/issues/54387#issuecomment-5737883099
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Needs Human ReviewThis issue has a backlog check awaiting maintainer review.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Human%20Review%22
on Sep 19, 2026https://github.com/microsoft/TypeScript/issues/54387#event-31427230819
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Copilothttps://github.com/apps/copilot-swe-agent
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Sep 19, 2026https://github.com/microsoft/TypeScript/issues/54387#event-31427231449
Copilothttps://github.com/apps/copilot-swe-agent
Accept union replacement values in String.replace #64330https://github.com/microsoft/TypeScript/pull/64330
on Sep 19, 2026https://github.com/microsoft/TypeScript/issues/54387#event-31427252763
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Needs Human ReviewThis issue has a backlog check awaiting maintainer review.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Human%20Review%22
on Sep 23, 2026https://github.com/microsoft/TypeScript/issues/54387#event-31704963178
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Help Wantedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Help%20Wanted%22
on Nov 10, 2026https://github.com/microsoft/TypeScript/issues/54387#event-35721530964
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/54387
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/54387
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Copilothttps://github.com/apps/copilot-swe-agent
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20lib.d.ts%22
BacklogNo due datehttps://github.com/microsoft/TypeScript/milestone/29
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.