[v8] ColumnMeta in module declaration giving other errors now #4157
-
I'm trying to add So I have a column def like:
and when rendering the table I use:
to add this Now off course typeScript complains about the
but now TypeScript starts to complain about the the
Do I need to add something else to the module declaration? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
This is a ongoing problem Tanner mentioned that he is working on a solution in this thread. I was struggling with this yesterday and I ended up just putting some |
Beta Was this translation helpful? Give feedback.
-
Don't forget to import import '@tanstack/react-table';
declare module '@tanstack/react-table' {
interface ColumnMeta {
className?: string
}
} |
Beta Was this translation helpful? Give feedback.
-
WOrks for me during runtime but not during build time 🤔 |
Beta Was this translation helpful? Give feedback.
-
To add custom properties to the ColumnMeta interface in @tanstack/react-table, extend the module using TypeScript's declaration merging feature: Component declare module '@tanstack/react-table' {
interface ColumnMeta<TData extends RowData, TValue> {
align?: 'left' | 'right' | 'center';
className?: string;
showVisibilitySettings?: boolean;
[key: string]: any; // Allows additional custom properties
}
} Usage in const columns: ColumnDef<DataRow>[] = [
{
accessorKey: 'name',
header: 'Name',
meta: {
align: 'left',
className: 'text-center',
showVisibilitySettings: true,
foo: "as you wish" // Users can add any custom properties they need in the meta field of the column definitions.
},
},
// Define other columns
]; |
Beta Was this translation helpful? Give feedback.
Don't forget to import
@tanstack/react-table
otherwise everything will be typed as any except ColumnMeta.