Skip to content
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

feature(toPayload): use generics #196

Closed
jotatoledo opened this issue Jul 26, 2017 · 1 comment
Closed

feature(toPayload): use generics #196

jotatoledo opened this issue Jul 26, 2017 · 1 comment

Comments

@jotatoledo
Copy link


[x] Feature request

What is the current behavior?

Currently, using .map(toPayload) will return an Observable<any> as result.

In most cases, developers will use toPayload to extract the information of an already filtered action (with ofType operator), so they know exactly what the action looks like and what is the type of the contained payload. But still, the type of it gets lost, what can result in typos or other problems.

Expected behavior:

Calling .map(toPayload) should be type aware; with this I mean that the type of the payload should be relevant for the resulting Observable stream,

This could be easily archieved by passing a type value to the function, so that the returned value matches the passed type. For example, the definition of the function could be changed to the following:

export function toPayload<T = any>(action: Action):  T {
  return (action as any).payload;
}

And then the function should be used as follows:

.map(toPayload<SomeInterface>)

Could this be possible?

Thanks in advance.

@jotatoledo
Copy link
Author

Just noticed that this was already addressed by #161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants