Operator '+' Cannot Be Applied to Types 'Number' and '1'

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

buildQuerySpec() {
  return {
    PageSize: this.paging.PageCount,
    CurrentPage: this.paging.PageIndex + 1,
    MaxSize: '',
    Filters: this.filter,
    OrderFields: [],
    IsDescending: false
  };
}

what is wrong with

 CurrentPage: this.paging.PageIndex + 1,

pageIndex is number , no idea really.

1

2 Answers

Googling the error message leads you to 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.

/* WRONG */
function reverse(s: String): String;

Do use the types number, string, and boolean.

/* OK */
function reverse(s: string): string;

In other words, replace the type Number with number.

1

Alternatively, you can try adding the unary operator + like,

CurrentPage: +this.paging.PageIndex + 1

which will also work in your case.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest