https://reasonml.org/docs/reason-compiler/latest/new-bucklescript-syntax says:
- Interpolated string: from
{j|hello ${name}|j}toj`hello ${name}`. - …
-
`foo bar`for multiline strings."foo bar"string is now singleline.
Why do interpolated strings need to have that j prefix? Can’t we just allow strings with backquotes both to be multiline and interpolated? (For that matter, why j and not i like “interpolated” or something else altogether?)
In any case, I will not use them as long as they are not typesafe. I have been bitten by this several times in situations like
{j|User: ${user}|j}
with user being a string, but later refactored to a record, resulting in
User: [object Object]
without the compiler catching this. I have therefore removed all string interpolation from my Reason code.
IMHO the way it should work is
- use just backquotes
- allow arbitrary expressions within the
${}as long as the type is string
Example:
`User: ${user.firstName}`

