This code:
throw new Error(`NODE_ENV set to invalid value: ${process.env.NODE_ENV}.`);
Gives the error:
21: throw new Error(`NODE_ENV set to invalid value: ${process.env.NODE_ENV}.`);
^^^^^^^^^^^^^^^^^^^^ undefined. This type cannot be added to
21: throw new Error(`NODE_ENV set to invalid value: ${process.env.NODE_ENV}.`);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string
Which isn't correct...that should be fine I think? Previous flow versions did not complain, but I started seeing these after I upgraded to:
Flow, a static type checker for JavaScript, version 0.28.0
Change log mentions this:
Variables in template literals are now subject to the same rules as variables being concatenated with a string using +. This may surface template strings with variables that may not safely coerce to a string
Ah, missed that.
Sad.
Why isn't boolean considered safe?
@arv It's less about being safe than it is about being intentional. When Flow was allowing coercion people were putting things into strings by mistake. By requiring it to be explicit we surface these issues.
Yeah, @thejameskyle is absolutely right. I just want to add that this change made string concatenation with + and string concatenation with template literals consistent. We are still open to changing the rules for both. For example, we don't require explicit casts for numbers, because patterns like 0 + "%" are so incredibly common. We're not so stuck in our ways :)
Most helpful comment
Yeah, @thejameskyle is absolutely right. I just want to add that this change made string concatenation with
+and string concatenation with template literals consistent. We are still open to changing the rules for both. For example, we don't require explicit casts for numbers, because patterns like0 + "%"are so incredibly common. We're not so stuck in our ways :)