no-useless-template-literals
Disallow unnecessary template literals.
🔒
Extending "plugin:@typescript-eslint/strict-type-checked"
in an ESLint configuration enables this rule.
💭
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"
}
};
Examples
- ❌ Incorrect
- ✅ Correct
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 Playgroundconst ab1 = 'ab';
const ab2 = 'ab';
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 PlaygroundOptions
This rule is not configurable.
When Not To Use It
When you want to allow string expressions inside template literals.