Skip to content
Advertisement

Operator ‘+’ cannot be applied to types ‘Number’ and ‘1’

I am getting an error when Operator ‘+’ cannot be applied to types ‘Number’ and ‘1’

JavaScript

what is wrong with

JavaScript

pageIndex is number , no idea really.

Advertisement

Answer

Googling the error message leads you to https://github.com/Microsoft/TypeScript/issues/2031 which pretty much explains the reason why it does not work.

You can also have a look at the Do’s and Don’ts Section:

Number, String, Boolean, and Object

Don’t ever use the types Number, String, Boolean, or Object. These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code.

JavaScript

Do use the types number, string, and boolean.

JavaScript

In other words, replace the type Number with number.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement