You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
What is the current behavior?
Currently, using
.map(toPayload)
will return anObservable<any>
as result.In most cases, developers will use
toPayload
to extract the information of an already filtered action (withofType
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:
And then the function should be used as follows:
.map(toPayload<SomeInterface>)
Could this be possible?
Thanks in advance.
The text was updated successfully, but these errors were encountered: