Replies: 3 comments 2 replies
|
I created a reproduction sandbox here: https://codesandbox.io/s/tanstack-table-react-type-error-reproduction-ii092f Although I have no idea why but I am receiving a different but slightly less scary looking error... once again have no idea "why" 😰 Error: |
Hey dont know if this help, but it help me, i declare the generic types like in shadcn data table, the problem happen on storybook (not a problem or bug really, is mostly typescript cannot infer it i think) interface ReusableTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
data: TData[]
}
export function ReusableTable<TData, TValue>({
data,
columns,
}: ReusableTableProps<TData, TValue>) {so to use it in a story will be like const meta = {
title: 'Components/Table',
component: ReusableTable<User, ColumnDef<User>>,
} satisfies Meta<typeof ReusableTable<User, ColumnDef<User>>>;you can use it in any other component though without passing the data type, cause it will get inferred <ReusableTable data={users} columns={userColumns} /> |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
So I am trying to make a basic table generic. The idea is I want to pass in any data and columns and if the data has what columns is trying to render it just does the work.
I archived this in v7 with a ton of pain and global types. So I am excited about re-implementing this in v8 without global types. I have it 90% of the way there but
ColumnDefis complaining about the generic overwrite and I cant figure out if its be or some kind of type inheritance bug or what.I am not quote yet a TypeScript power user so I am trying to understand the "why" here.
My table code:
My Storybook code where I am passing in props:
My TypeScript error:
So when I read this it looks like Typescript is saying
objectis not assignable toPersonbut Person is an object and that is exactly what I want so why not?Update: TabStack Table React to 8.3.0 and got a slightly different error
All reactions