Skip to content

Type the Actions stronger + several smaller changes

Antoine requested to merge ZeHiro/kresus:improve-ts-store into master

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 via action.status (instead of const {status} = action that action.err is accessed only when action.status === FAIL.
    This allowed to detect a small error in the code (it is not a bug itself), requiring to use æssertDefined: the id key can be undefined on a Partial<Category>.

Merge request reports

Loading