Search Terms
"template literal"
There are many hits, some which seem related, but everything I could find was a much bigger ask or wider in scope
Suggestion
Add a compiler option to enforce using only strings in ES6 string template literals
Use Cases
When using string literals, any variables are coerced to strings, which can lead to undesirable behavior.
As far as I can tell there's no way to avoid this behaviour. In the spirit of tying everything, I'd prefer that only actual string types are permissible for use in string templates to avoid accidental coercion by passing null, undefined or object types that may have unexpected string representations, and force users to explicitly convert them to strings.
Examples
For example:
function formatName(name: string | null): string {
return `Name is: ${name}`;
}
formatName(null) === "Name is: null"
Ideally the compiler would fail since name can be null.
Checklist
My suggestion meets these guidelines:
Search Terms
"template literal"
There are many hits, some which seem related, but everything I could find was a much bigger ask or wider in scope
Suggestion
Add a compiler option to enforce using only strings in ES6 string template literals
Use Cases
When using string literals, any variables are coerced to strings, which can lead to undesirable behavior.
As far as I can tell there's no way to avoid this behaviour. In the spirit of tying everything, I'd prefer that only actual
stringtypes are permissible for use in string templates to avoid accidental coercion by passing null, undefined or object types that may have unexpected string representations, and force users to explicitly convert them to strings.Examples
For example:
Ideally the compiler would fail since
namecan be null.Checklist
My suggestion meets these guidelines: