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

Disable coersion of addition of number and string. #4610

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/typing/flow_js.ml
Expand Up @@ -6114,8 +6114,8 @@ and needs_resolution = function
* is that we would error on both l and r, saying neither is compatible with
* `string`.
*
* We are less permissive than the spec when it comes to string coersion:
* only numbers can be coerced, to allow things like `num + '%'`.
* Unlike the spec, we do not allow string coersion:
* for example, numbers cannot be coerced, so `num + '%'` is invalid.
*
* TODO: handle symbols (which raise a TypeError, so should be banned)
*
Expand All @@ -6125,9 +6125,7 @@ and flow_addition cx trace use_op reason flip l r u =
let (l, r) = if flip then (r, l) else (l, r) in
let loc = aloc_of_reason reason in
begin match l, r with
| DefT (_, StrT _), DefT (_, StrT _)
| DefT (_, StrT _), DefT (_, NumT _)
| DefT (_, NumT _), DefT (_, StrT _) ->
| DefT (_, StrT _), DefT (_, StrT _) ->
rec_flow_t cx trace (StrT.at loc, u)

(* unreachable additions are unreachable *)
Expand Down