Type the Actions stronger + several smaller changes
This MR gathers several changes, I can split the MR if needed:
- The first commit renames the pure typescript files from file.tsx to file.ts. TSX extension is normally dedicated to files including JSX components. The store does not use JSX. The main reason for the renaming is that some TS semantics are not allowed in TSX files (due to the possible confusion with JSX balises).
- The second commit is just to migrate one more helper to typescript (needed for the last commit).
- The last commit is the core of this MR. It addresses the following problem:
The current typing of Actions does not allow to take advantage of TS in reducers:
action.someUnknownKey
(not defined in the actionCreator) can be accessed or set without tyescript complaining. The implementation I propose allows this extra check.
It also allows, when the check over status is done viaaction.status
(instead ofconst {status} = action
thataction.err
is accessed only whenaction.status === FAIL
.
This allowed to detect a small error in the code (it is not a bug itself), requiring to useæssertDefined
: theid
key can be undefined on aPartial<Category>
.