0

I have tried using // @ts-ignore which removes the error from my IDE, but in the terminal the error persits so the app does not compile. Any idea how to get around this?

https://www.npmjs.com/package/reactable < This Library is cuasing the TypeScript error when I add in the sort function from the documentation:

  <Table
      className="reactTable"
      data={this.state.documents}
      sortable={[
        'Name',
        'Scheduled Review Date',
        'Path',
        // @ts-ignore
        // tslint:disable-next-line
        {column: 'Column Name', sortFunction: function(a, b){
          return a > b ? 1 : -1;
        }},
        'Site',
        'Last Review Date'
      ]}
      itemsPerPage={7}
    />

[09:16:17] Error - [tsc] src/webparts/kim/components/Kim.tsx(271,11): error TS2322: Type '(string | { column: string; sortFunction: (a: any, b: any) => 1 | -1; })[]' is not assignable to type 'boolean | string[]'. [09:16:17] [tsc] Type '(string | { column: string; sortFunction: (a: any, b: any) => 1 | -1; })[]' is not assignable to type 'string[]'. [09:16:17] [tsc] Type 'string | { column: string; sortFunction: (a: any, b: any) => 1 | -1; }' is not assignable to type 'string'. [09:16:17] [tsc] Type '{ column: string; sortFunction: (a: any, b: any) => 1 | -1; }' is not assignable to type 'string'.

5
  • 1
    What kind of errors? Add them (or some of them) to the question! Mar 27, 2020 at 17:08
  • 1
    Are they not valid errors? Can you share examples? Mar 27, 2020 at 17:13
  • @RuneSperre I have added examples :)
    – BennKingy
    Mar 30, 2020 at 8:14
  • I think you must include more of your code -- how have you implemented the sort function in your table? Mar 30, 2020 at 8:38
  • @RuneSperre I have added more of the code, but the library I'm using for the table will have the sort function on the table
    – BennKingy
    Mar 30, 2020 at 8:46

2 Answers 2

1

I managed to both suppress the errors in the IDE and get the project to build by using ts-lint:disable as the first line in the file, while citing the exact rule(s) to disable, so something like

/* ts-lint:disable:no-any max-line-length */
import Something from 'something';

export default class Foo {
    // etc
}
1
  • Not working sadly, /* ts-lint:disable at the top of the file should suppress the error buts it not
    – BennKingy
    Mar 30, 2020 at 8:45
0

Clicking into the Table component and updating the interface to use any sortable?: any | string[] | boolean; fixed the errors. Bit of hack but nothing else was working!

Final solution:

    {column: 'Scheduled Review Date', sortFunction: function(a, b){
      var dateA = moment(a, 'DD-MM-YYYY'), dateB = moment(b, 'DD-MM-YYYY');
      if (dateA < dateB) { // a comes first
        return -1
      } else if (dateB < dateA) { // b comes first
          return 1
      } else { // equal, so order is irrelevant
          return 0 
      }
    }},

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.