Discriminating Unions using interfaces

25 Views Asked by At

I want to override an interface from a module but use some sort of discriminating unions using interfaces

export type CellValue = string | number | boolean | Media | null | undefined;

declare module '@tanstack/react-table' {
  interface ColumnMeta<TData extends RowData, TValue extends CellValue> {
    type?: 'text' | 'number' | 'date' | 'select' | 'file';
    options?: Option[] | string[] | readonly string[];
    updateColumn?: (currentValue: TValue, value: TValue) => TValue;
    inputAttributes?: React.InputHTMLAttributes<HTMLInputElement>;
  }
}

where i want the type TValue to change depending on the type of type

so when type is 'file' then TValue should be of type Media and the rest are like so:

type TypeMap = {
  text: string;
  number: number;
  date: string;
  select: string;
};

How can i do this ?

0

There are 0 best solutions below