要求加法的两个操作数都是相同的类型,并且是“bigint”、“number”或“string”。
规则配置
// code-linter.json5
{
"rules": {
"@typescript-eslint/restrict-plus-operands": "error"
}
} 正例
const num = 10;
const bigIntNum = 1n;
export const foo1 = parseInt('5.5', num) + num;
export const foo2 = bigIntNum + bigIntNum; 反例
const num = 10;
const bigIntNum = 1n;
export const foo2 = bigIntNum + num;