I have this example:
type Getter = (myRecord: Record<string, string>) => string;
type Order = { id: string; items: string };
const getItemsFromOrder = (order: Order) => order.items;
const someHook = (getValue: Getter) => {
// Contents don't matter
};
someHook(getItemsFromOrder);
My thinking is that this should work, since getItemsFromOrder
is a function that takes param that is Order
, which is a more specific case of Getter
. However I get the error
Argument of type '(order: Order) => string' is not assignable to parameter of type 'Getter'.
Types of parameters 'order' and 'myRecord' are incompatible.
Type 'Record<string, string>' is missing the following properties from type 'Order': id, items
Why does someHook
care that Getter
is not assignable to Order
? That’s not what I’m trying to do – I’m trying to assign Order
to Getter
, which should work, shouldn’t it?
How can I resolve this?