简体   繁体   中英

get error The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type

In the Angular2 when i was try to execute the below code i got the error

var intVal = function(i) {
    return typeof i === 'string'
    ? i.replace(/[\$,]/g, '') * 1
    : typeof i === 'number'
        ? i
        : 0;
};

error

The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

How to fix this error?

you use i.replace(/[\\$,]/g, '') * 1 . replace returns a string.

Try using +i.replace(/[\\$,]/g, '') * 1 to see ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM