'How can I specify the type of a dispatch function passed as a prop to a child component?
I have a dispatch function called dispatchFetch that I need to pass from the parent component to the child component, and as I am using TypeScript, I need to declare the type in the child component.
My parent component contains the following code:
<ProductionSchedule
dispatchFetch={ dispatchFetch }
/>
The child component (ProductionSchedule) contains the following:
export interface Props {
dispatchFetch: Dispatch;
};
TypeScript throwing the following error: Type 'Dispatch<Action>' is not assignable to type 'Dispatch<AnyAction>'.
Hovering over the prop, in the parent component I can see that the type is React.Dispatch<Action>, and in the child component the type is Dispatch<AnyAction>.
I have already explicitly set the type in the child to be <Dispatch>, and setting it to be Dispatch<Action> does not work either. How can I ensure that the types match?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
