Skip to main content

no-useless-template-literals

Disallow unnecessary template literals.

💭

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.

Resources