Add optional generic constraint for FSA type property #113
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.
Payload
type constaint optional (default toundefined
) to allow shorthand FSA declarations for Actions without payloads.Type
type constraint (defaults tostring
) to allow shorthand FSA declarations for strong typing of thetype
property.In TypeScript it is common to define actions with the
type
property declared astype: typeof ACTION_TYPE
.Thus, we might as well add an additional optional type constraint on the
FSA
type to express this.For a Counter application example this makes it possible to change the following code:
to this:
removing the need to re-declare the
type
property. The need to explicitly define theMeta
type asundefined
is unfortunate, but cannot be avoided if backwards compatability is to be maintained.The type is optional (defaults to
string
) and is added as a 3rd constraint and thus maintains backwards compatability.