String.prototype.concat()
should accept Array<mixed>
, not only Array<string>
#8728
Labels
Library definitions
Issues or pull requests about core library definitions
Missing/Incorrect APIs
String.prototype.concat
should allow any type as its arguments.concat(...values: Array<string>): string
should beconcat(...values: Array<mixed>): string
Relevant documentation
According to the MDN docs for the
concat()
method of theString
built-in type:Passing numbers, objects, etc to
String.prototype.concat
is is valid JS behavior but causes an error in Flow.This is important because the alternative to String#concat is the
+
operator, but that operator is problematic because using+
to concatenate a string to an object will causevalueOf
to be called on the object before it's coerced to a string. Some types (notably the new ECMAScript "Temporal" date/time API that's currently in Stage 3) will throw whenvalueOf
is called so that users don't inadvertently use<
or>
to compare objects that have specialized comparison methods.BTW, I discovered this Flow problem while fixing React's use of the
+
operator on strings and objects, because React was crashing and/or displaying confusing error messages when Temporal instances were rendered or used as props. This issue is causing facebook/react#22064 to fail its Flow check.PR coming!
The text was updated successfully, but these errors were encountered: