unnecessaryTemplateExpressions
Reports template expressions that can be replaced with simpler expressions.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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.
Examples
Section titled “Examples”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}`;const name = "Alice";const greeting = `Hello, ${name}!`;const first = "Banana";const last = "Cherry";const full = `${first} ${last}`;const count = 42;const message = `Count: ${count}`;const name = "Alice";const greeting = name;const count = 42;const countString = String(count);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.