Tanstack Table meta generic type

32 Views Asked by At

I want to pass react hook form useForm return object to the meta of the tanstack table. But I've a problem with type mapping for the values.

Doing this

declare module '@tanstack/react-table' {
  interface TableMeta<TData extends RowData> {
    formMethods?: UseFormReturn<any>;
  }
}

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 }} 
/>

How can I make it so it will infer the type and I can use the formMethods respectively typed to the type I pass to the useForm.

0

There are 0 best solutions below