Skip to content

Commit 7ce2344

Browse files
committed
Allow mixed args to string.prototype.concat()
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>`.
1 parent f9afdbc commit 7ce2344

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,11 @@ declare class String {
11031103
codePointAt(index: number): number;
11041104
/**
11051105
* Returns a string that contains the concatenation of two or more strings.
1106-
* @param strings The strings to append to the end of the string.
1106+
* If the arguments are not of the type string, they are converted to string values before
1107+
* concatenating.
1108+
* @param values The values to append to the end of the string.
11071109
*/
1108-
concat(...strings: Array<string>): string;
1110+
concat(...values: Array<mixed>): string;
11091111
constructor(value?: mixed): void;
11101112
/**
11111113
* Returns true if the sequence of elements of searchString converted to a String is the

newtests/autocomplete/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default (suite(({addFile, flowCmd}) => [
158158
},
159159
{
160160
"name": "concat",
161-
"type": "(...strings: Array<string>) => string"
161+
"type": "(...values: Array<mixed>) => string"
162162
},
163163
{
164164
"name": "endsWith",

tests/autocomplete/autocomplete.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Flags: --pretty
4141
{"name":"charAt","type":"(pos: number) => string"},
4242
{"name":"charCodeAt","type":"(index: number) => number"},
4343
{"name":"codePointAt","type":"(index: number) => number"},
44-
{"name":"concat","type":"(...strings: Array<string>) => string"},
44+
{"name":"concat","type":"(...values: Array<mixed>) => string"},
4545
{
4646
"name":"endsWith",
4747
"type":"(searchString: string, position?: number) => boolean"
@@ -389,7 +389,7 @@ Flags: --pretty
389389
{"name":"charAt","type":"(pos: number) => string"},
390390
{"name":"charCodeAt","type":"(index: number) => number"},
391391
{"name":"codePointAt","type":"(index: number) => number"},
392-
{"name":"concat","type":"(...strings: Array<string>) => string"},
392+
{"name":"concat","type":"(...values: Array<mixed>) => string"},
393393
{
394394
"name":"endsWith",
395395
"type":"(searchString: string, position?: number) => boolean"

0 commit comments

Comments
 (0)