typescripttslint

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


Solution

  • 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)}`