My goal is to achieve the following functionality:
const columns: ColumnDefinition<Pair>[] = [
{ label: 'Pair', value: pair => (all ? pair.code : pair.second.code), format: result => result.toUpperCase() },
{ label: 'Price', numeric: true, value: pair => 0 },
{ label: 'Change', numeric: true, value: pair => 0 },
];
and I want TypeScript to infer that the pair
parameter for value
is of type Pair
and the result
parameter for format
is of type string
(as pair.code
is a string
). The output of value
should be used as input for format
, with each column definition potentially having a different return type for value
.
This is my current type definition:
export type ColumnDefinition<T, F extends (item: T) => unknown> = {
label?: string;
numeric?: boolean;
value: F;
format?: (value: ReturnType<F>) => string;
};
However, I am encountering an error message:
Generic type 'ColumnDefinition' requires 2 type argument(s).