Skip to content

Commit

Permalink
fix(eslint-plugin): [restrict-plus-operands] consider template litera…
Browse files Browse the repository at this point in the history
…l types as strings (#3234)
  • Loading branch information
Josh Goldberg committed Apr 5, 2021
1 parent 0913f40 commit ccfd68e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/restrict-plus-operands.ts
Expand Up @@ -57,7 +57,10 @@ export default util.createRule<Options, MessageIds>({
if (type.isNumberLiteral()) {
return 'number';
}
if (type.isStringLiteral()) {
if (
type.isStringLiteral() ||
util.isTypeFlagSet(type, ts.TypeFlags.TemplateLiteral)
) {
return 'string';
}
// is BigIntLiteral
Expand Down
Expand Up @@ -110,6 +110,12 @@ const x = a + b;
declare const a: 'string literal' & string;
declare const b: string;
const x = a + b;
`,
`
function A(s: string) {
return \`a\${s}b\` as const;
}
const b = A('') + '!';
`,
{
code: `
Expand Down

0 comments on commit ccfd68e

Please sign in to comment.