From 7ce2344e5579fb13a8dab997c62e7af9538c84b1 Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Mon, 16 Aug 2021 14:14:15 -0700 Subject: [PATCH] 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` -> `Array`. --- lib/core.js | 6 ++++-- newtests/autocomplete/test.js | 2 +- tests/autocomplete/autocomplete.exp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/core.js b/lib/core.js index 993ec5b8422..024a51f0dbf 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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; + concat(...values: Array): string; constructor(value?: mixed): void; /** * Returns true if the sequence of elements of searchString converted to a String is the diff --git a/newtests/autocomplete/test.js b/newtests/autocomplete/test.js index d06511a62f4..cba395fa27d 100644 --- a/newtests/autocomplete/test.js +++ b/newtests/autocomplete/test.js @@ -158,7 +158,7 @@ export default (suite(({addFile, flowCmd}) => [ }, { "name": "concat", - "type": "(...strings: Array) => string" + "type": "(...values: Array) => string" }, { "name": "endsWith", diff --git a/tests/autocomplete/autocomplete.exp b/tests/autocomplete/autocomplete.exp index 244c164beca..562e0dd1e78 100644 --- a/tests/autocomplete/autocomplete.exp +++ b/tests/autocomplete/autocomplete.exp @@ -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"}, + {"name":"concat","type":"(...values: Array) => string"}, { "name":"endsWith", "type":"(searchString: string, position?: number) => boolean" @@ -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"}, + {"name":"concat","type":"(...values: Array) => string"}, { "name":"endsWith", "type":"(searchString: string, position?: number) => boolean"