I am dealing with a typescript error that I really do not understand and am not able to solve. Not a dealbreaker but the red line triggers me (I am sure you understand ;)).
Using Tanstack DataTable in my NextJS app. Using Supabase for the backend so I generated the types from Supabase as explained here:
https://supabase.com/docs/guides/api/rest/generating-types
My data-table.tsx is as follows (no errors there)
'use client'
import {
ColumnDef,
flexRender,
getCoreRowModel,
useReactTable,
} from '@tanstack/react-table'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData>[]
data: TData[]
}
export function DataTable<
TData extends TValue,
TValue extends {
id: string
name: string
email: string
user_id: string
created_at: string
}
>({ columns, data }: DataTableProps<TData, TValue>) {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
})
return (
<div className='border rounded-md'>
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<TableHead key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
)
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && 'selected'}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={columns.length} className='h-24 text-center'>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
)
}
My columns.tsx is as follows
'use client'
//removed imports for clarity
import { Tables } from '@/types/supabase'
export const columns: ColumnDef<Tables['clients']>[] = [
{
accessorKey: 'name',
header: 'Name',
},
{
accessorKey: 'email',
header: 'Email',
},
{
accessorKey: 'created_at',
header: 'Created At',
},
{
id: 'actions',
cell: ({ row }) => <Actions {...row.original} />,
},
]
const Actions = (client: Tables<'clients'>) => {
const [dialog, setDialog] = useState(null)
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant='ghost' className='w-8 h-8 p-0'>
<span className='sr-only'>Open menu</span>
<MoreHorizontal className='w-4 h-4' />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align='end'>
<DropdownMenuItem onClick={() => setDialog('update')}>
Edit
</DropdownMenuItem>
<DropdownMenuItem>
<Link href={`/clients/${client.id}`}>View cards</Link>
</DropdownMenuItem>
<DropdownMenuItem>View hours</DropdownMenuItem>
<DropdownMenuItem
className='text-red-400'
onClick={() => setDialog('delete')}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
{dialog === 'delete' && (
<DeleteClientDialog
client={client}
onOpenChange={setDialog}
open={dialog === 'delete'}
/>
)}
{dialog === 'update' && (
<UpdateClientDialog
open={dialog === 'update'}
client={client}
onOpenChange={setDialog}
/>
)}
</>
)
}
The error is on the Tables in
export const columns: ColumnDef<Tables[‘clients’]>[] = [
The error is this
Generic type 'Tables' requires between 1 and 2 type arguments.t