piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 98 forks source link

Is catchError(pipe(fetchTodosAsync.failure, of)) from the doc a legit syntax? #177

Closed goldenbearkin closed 5 years ago

goldenbearkin commented 5 years ago

I use the syntax catchError(pipe(fetchTodosAsync.failure, of)) follow the doc, but it doesn't work. I love the syntax, it is so clear, but is it legit?

piotrwitek commented 5 years ago

Hi @goldenbearkin, of course, it is :)

~Why wouldn't you try to git pull the repo, and open the sandbox project in your IDE, there is a reason I have added it there :)~

Ah sorry I was too fast, my bad. It's not in the repo, I'm going to check it tomorrow! Cheers!

piotrwitek commented 5 years ago

@goldenbearkin I believe it was working in the earlier version of TypeScript because the default type param was any. Not long ago it was changed to unknown in 3.5 or something, and now it is causing a type error in strict mode.

Unfortunately, it will not work anymore, I'll update the documentation.

Thanks for reporting.

piotrwitek commented 5 years ago

Actually there is more, it seems the root issue is in the rxjs types because of function is overloaded and it doesn't work well with the common pipe or compose implementations.

If you change of declaration to this declaration, it will work:

export declare function of<T>(a: T): Observable<T>;

Alternatively from is working just fine:

catchError(
  pipe(
    loadTodosAsync.failure,
    Array,
    from,
  )
)

Anyway, as a best alternative, I would just create a custom catchError wrapper to handle it more elegantly and actually there is a ticket for it somewhere in the repo that is WIP.