I am getting an error when Operator ‘+’ cannot be applied to types ‘Number’ and ‘1’
JavaScript
x
11
11
1
buildQuerySpec() {
2
return {
3
PageSize: this.paging.PageCount,
4
CurrentPage: this.paging.PageIndex + 1,
5
MaxSize: '',
6
Filters: this.filter,
7
OrderFields: [],
8
IsDescending: false
9
};
10
}
11
what is wrong with
JavaScript
1
2
1
CurrentPage: this.paging.PageIndex + 1,
2
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
, orObject
. These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code.JavaScript131/* WRONG */
2function reverse(s: String): String;
3
Do use the types
number
,string
, andboolean
.JavaScript131/* OK */
2function reverse(s: string): string;
3
In other words, replace the type Number
with number
.