redux-utilities / flux-standard-action

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

Add TypeScript definitions to enforce that `payload` and/or `meta` properties are defined. #112

Closed ryanmitts closed 5 years ago

ryanmitts commented 6 years ago

The issue I am having with the type definitions in this package are that the payload and meta properties on actions are marked optional.

When I define my own actions and extend the types using this package -- I know that some of my actions will and must always have a payload or meta property set.

With my TypeScipt compiler using the --strictNullChecks errors will be thrown when you try to access the payload or meta values as they could be undefined given the current definition of an FSA.

The work around would be to always do an if check to see if the properties are defined.

This is not very nice in your code.

I have proposed new definitions where you can specify and an FSA has a payload and/or meta property.

This has been documented in issue #109 .

This also fixes a small bug with the newer minor versions of Jest as documented in the commit message for that fix.

codecov[bot] commented 6 years ago

Codecov Report

Merging #112 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #112   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines           3      3           
  Branches        1      1           
=====================================
  Hits            3      3

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 98de5fe...dbabc94. Read the comment docs.

JaKXz commented 5 years ago

@ryanmitts thank you for the PR. I apologize for not getting back to you sooner, and now that #114 is also suggested, I would love to have a discussion there about what would be best. I do like the testing strategy that @couven92 came up with, do you think something similar would be possible here?

ryanmitts commented 5 years ago

@JaKXz I would just use the other PR to solve this problem -- I didn't know you could override the optional properties like that.

JaKXz commented 5 years ago

@ryanmitts great, thanks!