Skip to content

Commit

Permalink
Allow mixed args to string.prototype.concat()
Browse files Browse the repository at this point in the history
According to MDN docs for the `concat()` method of the `String` type:

> If the arguments are not of the type string, they are converted to string
> values before concatenating.

Passing numbers, objects, etc to `String.prototype.concat` is is valid JS
behavior but currently causes an error in Flow. It also may be blocking
facebook/react#22064.

This commit changes the arg type: `Array<string>` -> `Array<mixed>`.
  • Loading branch information
justingrant committed Aug 16, 2021
1 parent f9afdbc commit 7ce2344
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,11 @@ declare class String {
codePointAt(index: number): number;
/**
* Returns a string that contains the concatenation of two or more strings.
* @param strings The strings to append to the end of the string.
* If the arguments are not of the type string, they are converted to string values before
* concatenating.
* @param values The values to append to the end of the string.
*/
concat(...strings: Array<string>): string;
concat(...values: Array<mixed>): string;
constructor(value?: mixed): void;
/**
* Returns true if the sequence of elements of searchString converted to a String is the
Expand Down
2 changes: 1 addition & 1 deletion newtests/autocomplete/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default (suite(({addFile, flowCmd}) => [
},
{
"name": "concat",
"type": "(...strings: Array<string>) => string"
"type": "(...values: Array<mixed>) => string"
},
{
"name": "endsWith",
Expand Down
4 changes: 2 additions & 2 deletions tests/autocomplete/autocomplete.exp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Flags: --pretty
{"name":"charAt","type":"(pos: number) => string"},
{"name":"charCodeAt","type":"(index: number) => number"},
{"name":"codePointAt","type":"(index: number) => number"},
{"name":"concat","type":"(...strings: Array<string>) => string"},
{"name":"concat","type":"(...values: Array<mixed>) => string"},
{
"name":"endsWith",
"type":"(searchString: string, position?: number) => boolean"
Expand Down Expand Up @@ -389,7 +389,7 @@ Flags: --pretty
{"name":"charAt","type":"(pos: number) => string"},
{"name":"charCodeAt","type":"(index: number) => number"},
{"name":"codePointAt","type":"(index: number) => number"},
{"name":"concat","type":"(...strings: Array<string>) => string"},
{"name":"concat","type":"(...values: Array<mixed>) => string"},
{
"name":"endsWith",
"type":"(searchString: string, position?: number) => boolean"
Expand Down

0 comments on commit 7ce2344

Please sign in to comment.