redux-utilities / flux-standard-action

A human-friendly standard for Flux action objects.
MIT License
4.75k stars 142 forks source link

Adding types with optional properties made required #109

Open sstarrAtmeta opened 6 years ago

sstarrAtmeta commented 6 years ago

Properties payload, error, and meta are all optional properties according to documentation. However I believe there are cases where actions may need to make these properties required ( such as actions based around a text search ). Adding interfaces such as those suggested by @dsanders1234 in a previous issue about these options not being correctly typed as optional strikes me as a good approach, and I'm thinking of doing something similar as a workaround. The standard FluxStandardAction could remain in place while those additional versions could be used as needed.

JaKXz commented 6 years ago

@sstarrAtmeta are you still experiencing this pain? Would you like to take a stab at a PR? :)

fredrikhr commented 6 years ago

We now have two variants solving this issue: #112 and #114.

fredrikhr commented 5 years ago

@sstarrAtmeta with #114 now merged, you can now define the type by using FSAWithPayload to require a payload property. Or simply use FSAAuto which will infer whether payload should be required depending on whether you specify a type other than undefined.

unional commented 2 years ago

I think this can be closed. btw if you want to look for a more generic solution to this problem, there is a RequiredPick type from type-plus so that you can do:

type YourAction = RequiredPick<FSA<'ACTION', string>, 'payload'>