Skip to content

Commit

Permalink
better comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Jul 30, 2021
1 parent 4ef8071 commit cc02f67
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/middlewares/createRouterMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type RouterProps<
TRouteState = TUiState
> = {
router?: Router<TRouteState>;
// ideally stateMapping should be required if TRouteState is given,
// but there's no way to check if a generic is provided or the default value.
stateMapping?: StateMapping<TUiState, TRouteState>;
};

Expand All @@ -25,8 +27,11 @@ export const createRouterMiddleware = <
): InternalMiddleware<TUiState> => {
const {
router = historyRouter<TRouteState>(),
// technically this is wrong, as without stateMapping parameter given, the routeState *must* be UiState
stateMapping = (simpleStateMapping() as unknown) as StateMapping<
// We have to cast simpleStateMapping as a StateMapping<TUiState, TRouteState>.
// this is needed because simpleStateMapping is StateMapping<TUiState, TUiState>.
// While it's only used when UiState and RouteState are the same, unfortunately
// TypeScript still considers them separate types.
stateMapping = (simpleStateMapping<TUiState>() as unknown) as StateMapping<
TUiState,
TRouteState
>,
Expand Down

0 comments on commit cc02f67

Please sign in to comment.