Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix typing of `ofType` #289
Thanks @pelotom for the PR.
I'm worried it will prevent people from using things that aren't actually actions, like dispatching thunks or other objects that don't have the Action shape--because they're using some other middleware as well. I've seen this in the wild and think it should be supported. Thoughts?
My feeling is that I'd rather have a conservative default assumption of what you're dealing with (actions), and if the user knows they might also be dealing with something else they can override this assumption by making an explicit type cast. As opposed to assuming nothing whatsoever and having the default not be type safe. I also think that the majority of the time people are not using any other middleware if they're using
In the absence of this, I think most TypeScript users of
preferring the slightly more verbose but type safe
action$.filter(a => a.type === 'FOO')
Then again they might just use
action$selectMany(a => a.type === 'FOO' ? [a] : )
instead of either, because that provides an even more ideal typing (refining the type parameter of the resulting observable).
@jayphelps how do you figure? The observable's type parameter is not currently used in the parameter types for
ofType(...key: string): ActionsObservable<T>; ofType(...key: any): ActionsObservable<T>;
referenced this pull request
Aug 8, 2017
Hey @philcockfield, I think the main advantage of this approach is that types involved can be completely inferred without relying on a (possibly faulty, or missing) type annotation. The apparently massive changes introduced with this PR are mostly just fallout from introducing the