String.prototype.replace docs need fixing #47969
Labels
Experience Enhancement
Noncontroversial enhancements
Fix Available
A PR has been opened for this issue
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
lib Update Request
Configuration Check
My compilation target is
es2020
and my lib isthe default
.Missing / Incorrect Definition
The documentation for String.prototype.replace is confusing, and some of it is wrong.
Here are the definitions:
TypeScript/src/lib/es2015.symbol.wellknown.d.ts
Lines 221 to 233 in 1ad569f
TypeScript/src/lib/es5.d.ts
Lines 424 to 436 in 1ad569f
The first overload in es2015.symbol.wellknown.d.ts just plain has the wrong text, and it's also confusing because it says "or all matches with RegExp".
The first overload in es5.d.ts uses the phrase "for every successful match of searchValue in this string", which is technically correct I guess, but fails to mention that the only (applicable) case in which more than one match is even attempted is when searchValue is a RegExp with the
g
flag set (or at any rate, a RegExp where the spec equivalent of searchValue.global is considered true).Sample Code
This isn't about a failure to type-check, but a failure to explain.
Documentation Link
See https://tc39.es/ecma262/#sec-string.prototype.replace and https://tc39.es/ecma262/#sec-regexp.prototype-@@replace. (MDN isn't super clear on this particular method, either.)
N.B. there's PR in flight that touches the same code: #44348
The text was updated successfully, but these errors were encountered: