Wie der Versand einer Aktion oder eines ThunkAction (in Maschinenschrift, mit redux-thunk)?

Sagen, dass ich code wie folgt:

import { Action, Dispatch } from 'redux';
import { ThunkAction } from 'redux-thunk';

interface StateTree {
  field: string;
}

function myFunc(action: Action | ThunkAction<void, StateTree, void>,
                dispatch: Dispatch<StateTree>) {
  dispatch(action); //<-- This is where the error comes from
}

...Ich bekomme diese Fehlermeldung von der TypeScript-compiler:

ERROR in myFile.ts:x:y
TS2345: Argument of type 'Action | ThunkAction<void, StateTree, void>' is not assignable to parameter of type 'Action'.
  Type 'ThunkAction<void, StateTree, void>' is not assignable to type 'Action'.
  Property 'type' is missing in type 'ThunkAction<void, StateTree, void>'.

Ich glaube das problem ist, weil der Weg der redux-thunk type definition-Datei ergänzt die redux Dispatch - Schnittstelle und der Unfähigkeit Typoskript zu wissen, welche definition von Dispatch zu verwenden.

Gibt es eine Möglichkeit, um dieses?

Schreibe einen Kommentar