Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccfd68e

Browse files
author
Josh Goldberg
authored
fix(eslint-plugin): [restrict-plus-operands] consider template literal types as strings (typescript-eslint#3234)
1 parent 0913f40 commit ccfd68e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/eslint-plugin/src/rules/restrict-plus-operands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export default util.createRule<Options, MessageIds>({
5757
if (type.isNumberLiteral()) {
5858
return 'number';
5959
}
60-
if (type.isStringLiteral()) {
60+
if (
61+
type.isStringLiteral() ||
62+
util.isTypeFlagSet(type, ts.TypeFlags.TemplateLiteral)
63+
) {
6164
return 'string';
6265
}
6366
// is BigIntLiteral

packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ const x = a + b;
110110
declare const a: 'string literal' & string;
111111
declare const b: string;
112112
const x = a + b;
113+
`,
114+
`
115+
function A(s: string) {
116+
return \`a\${s}b\` as const;
117+
}
118+
const b = A('') + '!';
113119
`,
114120
{
115121
code: `

0 commit comments

Comments
 (0)