Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [restrict-plus-operands] consider template literal types as strings #3234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';
}
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
// 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