Repository navigation
feat(Store/Effects) Add toPayloadTyped function - #157
Closed
karptonite wants to merge 2 commits into
Closed
karptonite wants to merge 2 commits into
karptonite wants to merge 2 commits into
Conversation
bfricka
reviewed
Jul 23, 2017
| type: string; | ||
| } | ||
|
|
||
| export interface ActionWithPayload<T> { |
Contributor
There was a problem hiding this comment.
This should be:
export interface ActionWithPayload<T> extends Action {
payload: T;
}
Contributor
Author
There was a problem hiding this comment.
You are right! I had that at some point. I'll fix it.
Contributor
Author
|
Do not merge this! I think I may have figured out a way to do it without requiring a separate toPayload function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Third time's a charm)
For discussion, this may require some refinement.
But with the newly type safe version of
ofType, this opens up the option of a type safe version oftoPayloadas well. I wasn't able to retrofittoPayloadwithout breaking previous behavior, unfortunately (maybe someone who knows typescript better than my can give it a go?), but I was able to implement a separatetoPayloadTyped, which infers the type of the payload based on the Action.Is this useful? Is there an even cleaner way to implement it?
Note that this doesn't require that a user declare that their actions implement
ActionWithPayload(It is probably best to do so, but Typescript can infer that), but it DOES require that they declare the type of their action when they callofType.