0
votes

sorry for long subject, I just don't understand the response.

my code:

this.rezerwacjeFilteredByseaarchInput.sort(function (a, b) {
      if (a[5]===null) {
       // console.log(a[5]);
        return 1;

      }
        if (firmaSortOrder) {
          return a[5] > b[5];
        }
        else {
          return b[5] > a[5];
        }

    });

js throws: error TS2345: Argument of type '(a: Rezerwacja, b: Rezerwacja) => boolean | 1' is not assignable to parameter of type '(a: Rezerwacja, b: Rezerwacja) => number'. Type 'boolean | 1' is not assignable to type 'number'. Type 'true' is not assignable to type 'number'.

2
return a[5] - b[5], and b[5] - a[5]baao

2 Answers

1
votes

According to MDN description of sort function, sort compare function has to return a number. Your first condition returns number, but other two returns boolean values. Below code should work.

this.rezerwacjeFilteredByseaarchInput.sort(function (a, b) {
    if (a[5] === null) {
        return 1;
    }
    if (firmaSortOrder) {
        return a[5] - b[5];
    }
    return b[5] - a[5];
});
0
votes

This is a typescript compilation error. the signature in rezerwacjeFilteredByseaarchInput is incorrect. It should only return number values (this is what the message is saying ) but in its body you can read that it can return the boolean values.