Open mdodge-ecgrow opened 11 months ago
This is frustrating because, on this page: https://tanstack.com/table/v8/docs/api/core/table#usereacttable--createsolidtable--usevuetable--createsveltetable I searched for the term "filterFns" and got zero hits. So I have no idea why I am getting a typescript error saying that parameter is required.
Facing the same issue here. I'm using Next.js with pnpm. If that has something to do with this issue. 🤔
As @mdodge-ecgrow has mentioned, not defining "filterFns" throws typescript error.
Had the same problem. I looked in the code and found this in Filters.ts:
type ResolvedFilterFns = keyof FilterFns extends never
? {
filterFns?: Record<string, FilterFn<any>>
}
: {
filterFns: Record<keyof FilterFns, FilterFn<any>>
}
So I've checked if somewhere exists FilterFns implementations in the code, cleaned them out - and these exceptions disappeared.
Not sure if this helps, but we had the same error appear when we merged two branches, where each had a different table. One without filterFns defined worked fine before merge. After merge, it started complaining.
Turned out one of our devs added this piece of code to make the table filterable:
declare module '@tanstack/table-core' {
interface FilterFns { fuzzy: FilterFn<unknown> }
interface FilterMeta { itemRank: RankingInfo }
}
I'm 99% sure it was copied from Table filter examples (from main.tsx
) here: https://tanstack.com/table/v8/docs/examples/react/filters
I'm also 99% sure it is not needed for filtering to work.
@kubacichorski I must say that I think that you are incorrect and it is required, because I have this declaration in my code too and without it where you configure your columns and relate to a custom filter that you define, it shows a typescript error: Type '"fuzzy"' is not assignable to type FilterFnOptions<RowType>
Yes it might not be required for the tables filters to work but it does required by TS for dealing with these errors.
@Relaximus didn't you break any existing logic that was originally implemented by deleting these implementations for filterFns?
Related to this thread, I noticed this error shows to me when I tried to create a second table that shouldn't have custom filterFn, does anyone here know if it's possible to override a declared module?
I had the same issue, even when putting the declare in the file with the table I wanted to filter on (not in any shared code), which I guess makes sense. Defining the filters inline works, you just don't get the brevity of a named filter.
@AdirTrichter i have the same issue when deifing a custom filter how do i solve it i'm getting this error
Type '"myCustomFilterFn"' is not assignable to type 'FilterFnOption
I am facing the same problem.
@djshubs i ended up writing the function on all columns that i need it until i find out how to solve it
@djshubs i ended up writing the function on all columns that i need it until i find out how to solve it
Have you tried this? Makes sure filterFns stays optional.
declare module "@tanstack/table-core" {
interface TableOptions<TData extends RowData>
extends PartialKeys<TableOptionsResolved<TData>, "state" | "onStateChange" | "renderFallbackValue"> {
filterFns?: FilterFns;
}
interface FilterFns {
"=": FilterFn<unknown>;
contains: FilterFn<unknown>;
yourCustomFunction: FilterFn<unknown>
}
}
Describe the bug
This is probably not a bug, but I cannot figure out why my
useReactTable
call is saying that thefilterFns
property is required. This is the code where all the red squigglies are:Full error:
And here is my full component:
Your minimal, reproducible example
https://codesandbox.io/s/keen-aj-lxqrw8?file=/src/UsersTable.tsx
Steps to reproduce
Create the table with the following code:
Expected behavior
It should create the table and not throw any typescript errors about requiring 'filterFns'.
How often does this bug happen?
Every time
Screenshots or Videos
Platform
OS: Windows 11 Pro Browser: Firefox 115.0.3 64 bit
react-table version
8.9.3
TypeScript version
5.1.6
Additional context
I noticed in my sandbox example, there are no Typescript errors. So I'm not sure if it is something related to my IDE? I am using Webstorm 2023.2.
Terms & Code of Conduct