I’m using an internationalization library in JS (https://github.com/format-message/format-message) which contains a function that takes a template literal and an object. The template literals don’t have any interpolated JS variables, but the text has to be wrapped in backticks rather than quotes e.g. when translating ICU-formatted plural variants. Is there a way to type-check template literal parameters of external functions in Bucklescript?
Edit: The code I have currently looks like this:
[@bs.module] external i18n : (string, Js.Dict.t(string)) => string = "format-message";
let _getDisplayText = (~suffix, ~difference) => {
let differenceStr = string_of_int(difference);
let i18nMapArg = Js.Dict.empty();
Js.Dict.set(i18nMapArg, "difference", differenceStr)
switch (suffix) {
| Character => i18n([%bs.raw {|`{difference, plural, one {# character} other {# characters}}`|}], i18nMapArg)
| None => i18n([%bs.raw {|`{difference, number}`|}], i18nMapArg)
}
};
The signature for i18n()
isn't correct - the first parameter should be a template literal string specifically, not a plain string. Can I ensure that the first argument gets transpiled to a JS template literal string in a type-safe way?