close

no-unnecessary-template-expression

Added in v0.1.4

Configuration

PresetConfigured Value
✅ ts.configs.strictTypeChecked"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unnecessary-template-expression': 'error',
    },
  },
]);

Rule Details

Disallow unnecessary expressions inside template literals and template literal types.

Literal interpolations can be written directly into the surrounding template. When a template contains only one string-typed expression, the template wrapper can be removed entirely. The rule provides an autofix for both forms while preserving template escapes.

Examples of incorrect code for this rule:

const ab = `${'a'}`;
const greeting = `${name}`; // when name is typed as string
const value = `${true}`;
const num = `${100}`;
type EventName = `on${'Click'}`;

Examples of correct code for this rule:

const ab = 'a';
const greeting = name;
const combined = `Hello, ${name}!`;
const tagged = tag`${value}`;
type EventName = 'onClick';

Original Documentation