Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operands of '+' operation must either be both strings or both numbers. Consider using a template literal @typescript-eslint/restrict-plus-operands

I just using tslint but this block of code throws me a error.

 const MemberNumber = 'MBR' + pinCode + sliceNumber
Operands of '+' operation must either be both strings or both numbers. Consider using a template literal  @typescript-eslint/restrict-plus-operands

I tired with template method again throwing the tslint error.

const MemberNumber = `MBR${pinCode}${sliceNumber}`
 Invalid type "any" of template literal expression  @typescript-eslint/restrict-template-expres

how to fix this.

Thanks

like image 815
AsZik Avatar asked Jan 08 '21 05:01

AsZik


1 Answers

It looks like pinCode or sliceNumber is of type number, so converting it to a string should work:

const MemberNumber = `MBR${String(pinCode)}${String(sliceNumber)}`
like image 74
TkDodo Avatar answered Oct 06 '22 20:10

TkDodo