diff --git a/src/create-thunks.ts b/src/create-thunks.ts index 9b3f566..4014bbf 100644 --- a/src/create-thunks.ts +++ b/src/create-thunks.ts @@ -1,4 +1,4 @@ -interface Action { +interface ReduxAction { type: string; } @@ -10,9 +10,13 @@ interface GetState { (): unknown; } -type OnlyPromise = T extends (...args: any[]) => Promise - ? Promise - : T extends (...args: any[]) => infer R ? R : void; +/** + * For functions return its return type otherwise return void. + * + * Different from the core ReturnType which can oly be called for + * functions. + */ +type FunctionReturnValue = T extends (...args: any[]) => infer R ? R : void; class SimpleStore { private _reduxDispatch: ReduxDispatch; @@ -24,7 +28,9 @@ class SimpleStore { this.dispatch = this.dispatch.bind(this); } - dispatch(action: T): OnlyPromise { + dispatch( + action: T, + ): FunctionReturnValue { const ret = this._reduxDispatch(action); if (typeof action === "function") {