T
TanStack2y ago
reduced-jade

How to type meta with Generic

I want to pass react hook form useForm return to the meta of the tanstack table. Doing this
declare module '@tanstack/react-table' {
interface TableMeta<TData extends RowData> {
formMethods?: UseFormReturn<any>;
}
}
declare module '@tanstack/react-table' {
interface TableMeta<TData extends RowData> {
formMethods?: UseFormReturn<any>;
}
}
It works but type as any doesn't provide any type inference down the road when I use it with the table.
//const formMethods: UseFormReturn<{phoneNumber: string, openingHours: {mo: string, tu: string, we: string, th: string, fr: string, sa: string, su: string}}, any, {phoneNumber: string, openingHours: {mo: string, tu: string, we: string, th: string, fr: string, sa: string, su: string}}>
const formMethods = useForm<{
phoneNumber: string;
openingHours: {
mo: string;
tu: string;
we: string;
th: string;
fr: string;
sa: string;
su: string;
};
}>();


<Table
...
//here formMethods:UseFormReturn<any> | undefined
meta={{ formMethods }}
/>
//const formMethods: UseFormReturn<{phoneNumber: string, openingHours: {mo: string, tu: string, we: string, th: string, fr: string, sa: string, su: string}}, any, {phoneNumber: string, openingHours: {mo: string, tu: string, we: string, th: string, fr: string, sa: string, su: string}}>
const formMethods = useForm<{
phoneNumber: string;
openingHours: {
mo: string;
tu: string;
we: string;
th: string;
fr: string;
sa: string;
su: string;
};
}>();


<Table
...
//here formMethods:UseFormReturn<any> | undefined
meta={{ formMethods }}
/>
How can I make it so it will infer the type
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?