New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript Epic interface is missing dependencies parameter #231
Comments
I've been trying to think of the best way to handle this before TS gets generic param defaults (coming in the next version). I'd rather not do The real dependencies type needs to be inferred from what you pass to We also have to juggle this with the requests of #219 which is asking for a separate type for input vs output. |
Thanks! yes I can definitely see the issue. For now thanks to the |
Great to know. Thanks for reporting back. |
I'm facing the same issue. |
@rehia can you share the workaround you tried? |
@veeramarni sorry didn't see your post. Here I declare the epics, in which I use my dependencies: const prepareEpics = (dependencies) => ({
epic1: ...,
epic2: ...
}); And I export a function to combine them: export const buildEpic = (dependencies) =>
combineEpics(
...values(prepareEpics(dependencies))
); ( Then I use it as a middleware: const dependencies = {dependency1, dependency2};
applyMiddleware(
createEpicMiddleware(
buildEpic(dependencies)
)
) Hope this helps. |
Wouldn't something like my example below be totally fine, or do I miss something?
Many thanks for the great library! |
@rafaelkallis That would force people to have to pass a type for dependencies and include it in their epic function signatures, even if they don't use it..which isn't ideal but certainly not the end of the world. Default type param would solve this once enough people have switched to that TS version. There is also #219 which conflicts. |
Thanks @jayphelps for the very good argument, I also support that. May I also ask what the use case of this definition of
It perfectly solves the dependency type issue if used like follows:
Yet I'm struggling finding a way to use |
const rootEpic: CustomEpic = (action$, store) => combineEpics<CustomEpic>(epic1, epic2)(action$, store, custom1, custom2); I unfortunately don't have much time right now to dive deeper into this, but if you can get something working and it's ergonomic, definitely feel free to PR! I would love you long time. |
@jayphelps thanks for the interesting snippet provided. I was trying to hint towards something like this with my question:
such that it can be used like so:
But I guess it boils down to those default type params again. Nevertheless, thanks again for your response. If I find some spare time and hack something useful I may open a PR. |
Current declaration for the
Epic<T, S>
type is missing the last dependencies parameterInstead of:
export declare interface Epic<T, S> { (action$: ActionsObservable<T>, store: MiddlewareAPI<S>): Observable<T>; }
it should probably be
export declare interface Epic<T, S> { (action$: ActionsObservable<T>, store: MiddlewareAPI<S>, dependencies: any): Observable<T>; }
The text was updated successfully, but these errors were encountered: