table icon indicating copy to clipboard operation
table copied to clipboard

(TypeScript) Type definitions are incomplete for sortable tables.

Open alexkvazos opened this issue 5 years ago • 29 comments

Describe the bug (required) Some type definitions are incomplete -- in the column for example. Property 'getSortByToggleProps' does not exist on type 'HeaderGroup<object>'.ts(2339) Property 'isSorted' does not exist on type 'HeaderGroup<object>'.ts(2339) Property 'isSortedDesc' does not exist on type 'HeaderGroup<object>'.ts(2339)

Provide an example via Codesandbox! (required) https://codesandbox.io/s/react-table-incomplete-types-x1es6

Steps To Reproduce (required) Try to use useSortBy on react-table and consume the getSortByToggleProps function or isSorted and isSortedDesc properties on a TypeScript project.

Expected behavior (Recommended) The types shouldn't error

Screenshots Screen Shot 2021-01-05 at 20 55 25

This bug was reported without any information before and noticed they were also using TypeScript so I could only figure it was TypeScript specific. https://github.com/tannerlinsley/react-table/issues/1481

alexkvazos avatar Jan 06 '21 02:01 alexkvazos

I had a similar issue with another plugin. The solution i got, was creating folder called types in /src directory and then creating a file called react-table-config.d.ts. Then put the definitions that you can find in: types/react-table.

Now you can check: image

Example: https://codesandbox.io/s/react-table-incomplete-types-fixed-2r4us

Regards.

samyan avatar Jan 07 '21 20:01 samyan

Interesting, seems kinda hacky -- I wonder why its not part of the @types/react-table package in npm.

Thank you anyhow @samyan

alexkvazos avatar Jan 08 '21 04:01 alexkvazos

Interesting, seems kinda hacky -- I wonder why its not part of the @types/react-table package in npm.

Thank you anyhow @samyan

Ni idea pero estuve días dando vueltas y al final la solución más óptima fue esa. No hay de que.

Saludos.

samyan avatar Jan 08 '21 09:01 samyan

After some digging it appears that this is expected behaviour of the @types/react-table package, and it has documentation on how to include types for the table plugins that you are using, not ideal but presumably this is because the plugins are optional...

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table#configuration-using-declaration-merging

jamieweavis avatar Jan 17 '21 08:01 jamieweavis

Had this issue also, would love a resolution from the maintainers because setting it up locally doesn't scale too well with changes being made for this library.

yotam707 avatar Feb 02 '21 06:02 yotam707

After some digging it appears that this is expected behaviour of the @types/react-table package, and it has documentation on how to include types for the table plugins that you are using, not ideal but presumably this is because the plugins are optional...

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table#configuration-using-declaration-merging

In all fairness, the plugins don't feel all that optional as they are included in base package.

nikaupp avatar Feb 10 '21 19:02 nikaupp

https://codesandbox.io/s/react-table-incomplete-types-forked-0hdd1

@samyan The sandbox link seems to be not working. I am facing the same issue with ts. After creating a type defination file also I am getting the below error Parameter 'headerGroup' implicitly has an 'any' type.ts(7006)

dkumar431 avatar Mar 02 '21 07:03 dkumar431

https://codesandbox.io/s/react-table-incomplete-types-forked-0hdd1

@samyan The sandbox link seems to be not working. I am facing the same issue with ts. After creating a type defination file also I am getting the below error Parameter 'headerGroup' implicitly has an 'any' type.ts(7006)

Updated:

https://codesandbox.io/s/react-table-incomplete-types-fixed-2r4us

samyan avatar Mar 02 '21 09:03 samyan

Note for anyone having this problem. I just fought this for a number of hours and almost abandoned TS until I realized I had put the react-table-config.d.ts in the wrong location. My project looks like this:

/ 
 - /api
 - /client
   - /src

I needed this in my client app. I placed it in /client/types/react-table-config.d.ts and it did not work. Once I moved it into /client/src/types/ everything started working. Hope that helps someone.

donnfelker avatar Mar 04 '21 16:03 donnfelker

@samyan Your example saved me, just used your /types and boom. Thank you very much. Hope the mantainers take note of the problem

pedrogallon avatar Mar 25 '21 05:03 pedrogallon

The typing solution works for me as well - even though it's a global type. It seems to me like if you have different tables with different plugins typing them all globally that way will start to fall apart at some point. I'd love for some way to specify on a per-table basis what plugins the table uses.

GeeWee avatar May 25 '21 07:05 GeeWee

Still not working on 7.7.

  • "react-table": "^7.7.0",
  • "@types/react-table": "^7.7.1",

Property 'getSortByToggleProps' does not exist on type 'HeaderGroup<{ firstName: string; lastName: string; age: number; visits: number; progress: number; status: string; }>'.

OrderBy works but types is not correct.

image

tostavio avatar Jun 23 '21 15:06 tostavio

Still not working on 7.7.

  • "react-table": "^7.7.0",
  • "@types/react-table": "^7.7.1",

Property 'getSortByToggleProps' does not exist on type 'HeaderGroup<{ firstName: string; lastName: string; age: number; visits: number; progress: number; status: string; }>'.

OrderBy works but types is not correct.

image

Check it https://github.com/tannerlinsley/react-table/issues/2970#issuecomment-756364081

samyan avatar Jun 23 '21 19:06 samyan

Checking in on this issue - attached screenshot of the build errors I get, despite everything working properly. Also on v7.7

image

lararosekelley avatar Oct 21 '21 16:10 lararosekelley

I have the same issue, but the correction suggested by @samyan worked for me. btw Thanks for suggesting.

Kyhaiu avatar Nov 10 '21 20:11 Kyhaiu

Same issue for me. Did manually create the type file as @samyan suggested.

kristjaningi avatar Nov 26 '21 15:11 kristjaningi

This saved my project, thanks all

christianblandford avatar Dec 22 '21 17:12 christianblandford

What a weird solution. The types from the readme aren't even the same as those in the package. Adding those definitions breaks existing code.

finkrer avatar Feb 23 '22 10:02 finkrer

@samyan you're suggestions fix the initial file, but in the types file you provided, typescript now complains about:

All declarations of 'Row' must have identical type parameters. (for each interface declared there, its also happening in your codesandbox)

any ideas how to fix this? thx in advance.

drummerwolli avatar Feb 27 '22 19:02 drummerwolli

@samyan you're suggestions fix the initial file, but in the types file you provided, typescript now complains about:

All declarations of 'Row' must have identical type parameters. (for each interface declared there, its also happening in your codesandbox)

any ideas how to fix this? thx in advance.

I fixed by replacing Record<string, unknown> = Record<string, unknown> with object = {}

alexinfurs avatar Mar 04 '22 08:03 alexinfurs