You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to extend @tanstack/react-table by declaring a ColumnMeta interface where filterKey should have a type that depends on filterType. Specifically, I have a mapping like this:
declare module '@tanstack/react-table' {
interface ColumnMeta<TData extends RowData, TValue> {
filterType?: keyof FilterKeyTypeMap;
filterKey?: ???; // How to correctly infer this type based on filterType?
}
}
I want filterKey to be typed as follows:
If filterType is 'Text' or 'Number', then filterKey should be string.
If filterType is 'DateRange' or 'NumberRange', then filterKey should be string[].
How can I properly type filterKey so that TypeScript enforces the correct type based on filterType, while keeping ColumnMeta as an interface?
Any guidance or suggestions would be appreciated! 🚀
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to extend @tanstack/react-table by declaring a ColumnMeta interface where filterKey should have a type that depends on
filterType
. Specifically, I have a mapping like this:Here's my module declaration:
I want
filterKey
to be typed as follows:filterType
is 'Text' or 'Number', thenfilterKey
should be string.filterType
is 'DateRange' or 'NumberRange', thenfilterKey
should be string[].How can I properly type
filterKey
so that TypeScript enforces the correct type based onfilterType
, while keeping ColumnMeta as an interface?Any guidance or suggestions would be appreciated! 🚀
Beta Was this translation helpful? Give feedback.
All reactions