Skip to content

unnecessaryTemplateExpressions

Reports template expressions that can be replaced with simpler expressions.

✅ This rule is included in the ts logical and logicalStrict presets.

Template literals with a single substitution and no surrounding text are unnecessarily complex. Using the expression directly is clearer and more maintainable.

For example, `${value}` is functionally equivalent to String(value) but adds unnecessary syntax noise. Template literals should be reserved for cases where they provide clear value, such as embedding expressions within text or combining multiple values.

const name = "Alice";
const greeting = `${name}`;
const count = 42;
const message = `${count}`;
function getValue() {
return "result";
}
const output = `${getValue()}`;
const isActive = true;
const status = `${isActive}`;

This rule is not configurable.

If you have a coding standard that requires explicit string coercion using template literals for clarity or consistency, you might choose to disable this rule. However, in most cases, removing unnecessary template wrappers improves code readability.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.