Flow: allow add/concatenate string and boolean

Created on 30 May 2018  路  2Comments  路  Source: facebook/flow

Flow should allow a boolean to be appended/concatenated with a string just like currently is done with numbers. For example, this is ok in flow 0.73.0:

/* @flow */

function foo(s: string, x: number): string {
    return s+x;
}

But this gives an error:

/* @flow */

function foo(s: string, x: boolean): string {
    return s+x;
}
4:     return s+x;
                ^ Cannot add `s` and `x` because boolean [1] is incompatible with string [2].
References:
3: function foo(s: string, x: boolean): string {
                              ^ [1]
3: function foo(s: string, x: boolean): string {
                   ^ [2]

Most helpful comment

I'd say the opposite thing: flow should not allow to concatenate strings with numbers.

All 2 comments

I'd say the opposite thing: flow should not allow to concatenate strings with numbers.

The one that is annoying to me: number + boolean is allowed.

Was this page helpful?
0 / 5 - 0 ratings