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

Typo in String#match (lib.es2015.symbol.wellknown) #36299

Open
G-Rath opened this issue Jan 19, 2020 · 2 comments · May be fixed by #50452
Open

Typo in String#match (lib.es2015.symbol.wellknown) #36299

G-Rath opened this issue Jan 19, 2020 · 2 comments · May be fixed by #50452
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@G-Rath
Copy link

G-Rath commented Jan 19, 2020

TypeScript Version: 3.0.0-dev.201xxxxx

Search Terms:
typos, string, lib, es2015.symbol.wellknown


I've wiped the majority of the template since this is a typo report.
I was originally going to just make a PR but the template had:

  • There is an associated issue in the Backlog milestone (required)

The typo itself is that String#match in lib.es2015.symbol.wellknown has it's param description pasted in the middle of it's method description:

/**
* Matches a string an object that supports being matched against, and returns an array containing the results of that search.
* @param matcher An object that supports being matched against.
*/

My PR replaced it with "with a regular expression" - Let me know what the correct way to proceed with this is 🙂

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 21, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 21, 2020
@RyanCavanaugh RyanCavanaugh added the Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript label Jan 21, 2020
@G-Rath
Copy link
Author

G-Rath commented Feb 18, 2020

I've just found a similar typo in the RegExp interface in es5.lib:

TypeScript/src/lib/es5.d.ts

Lines 912 to 913 in d2c5d54

/** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */
readonly source: string;

The last part of the comment of the comment doesn't seem relevant:

The regExp argument is a Regular expression object. It can be a variable name or a literal.

My guess is that is the description for the regexp param taken by #match, which reads very similar:

TypeScript/src/lib/es5.d.ts

Lines 416 to 420 in d2c5d54

/**
* Matches a string with a regular expression, and returns an array containing the results of that search.
* @param regexp A variable name or string literal containing the regular expression pattern and flags.
*/
match(regexp: string | RegExp): RegExpMatchArray | null;

@sebmjoll
Copy link

sebmjoll commented Mar 6, 2020

I have found another comment issue in replace():

/**
 * Replaces text in a string, using an object that supports replacement within a string.
 * @param searchValue A object can search for and replace matches within a string.
 * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
 */
 replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;

This comment is misleading because this function replaces all occurrences when the pattern is a regular expression but only the first occurrence when it is a literal as explained in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace :

The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.

which is confirmed by running the following code:

console.log("foo".replace("o", "O")); // => fOo
console.log("foo".replace(/o/g, "O")); // => fOO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants