Skip to main content

no-useless-template-literals

Disallow unnecessary template literals.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

💭

This rule requires type information to run.

This rule reports template literals that can be simplified to a normal string literal.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-useless-template-literals": "error"
}
};

Try this rule in the playground ↗

Examples

const ab1 = `${'a'}${'b'}`;
const ab2 = `a${'b'}`;

const stringWithNumber = `${'1 + 1 = '}${2}`;

const stringWithBoolean = `${'true is '}${true}`;

const text = 'a';
const wrappedText = `${text}`;

declare const intersectionWithString: string & { _brand: 'test-brand' };
const wrappedIntersection = `${intersectionWithString}`;
Open in Playground

Options

This rule is not configurable.

When Not To Use It

When you want to allow string expressions inside template literals.


Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting. See Performance Troubleshooting if you experience performance degredations after enabling type checked rules.

Resources