Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RouterReducerState.state type is still RouterStateSnapshot even when using a custom RouterStateSerializer #289

Closed
FabienDehopre opened this issue Aug 17, 2017 · 0 comments

Comments

@FabienDehopre
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

What is the current behavior?

The RouterReducerState.state property is still of type RouterStateSnapshot even when using a custom RouterStateSerializer.

Expected behavior:

The RouterReducerState.state property type should be either the type of the RouterStateSerializer generic type or any.

Minimal reproduction of the problem with instructions:

Follow the instruction of the router-store api doc for creating a custom router state serializer and try to retrieve the router state. In typescript the type is wrong so you have to cast to any to access the custom properties of the router state.

export interface RouterStateUrl {
  url: string;
  params: Params;
  queryParams: Params;
  data: Data;
}

export class CustomRouterStateSerializer implements RouterStateSerializer<RouterStateUrl> {
  serialize(routerState: RouterStateSnapshot): RouterStateUrl {
    return {
      url: routerState.url,
      params: mergeRouteParams(routerState.root, r => r.params),
      queryParams: mergeRouteParams(routerState.root, r => r.queryParams),
      data: mergeRouteData(routerState.root)
    };
  }
}

function mergeRouteParams(route: ActivatedRouteSnapshot, getter: (r: ActivatedRouteSnapshot) => Params): Params {
  if (!route) {
    return {};
  }

  const currentParams = getter(route);
  const primaryChild = _.find(route.children, c => c.outlet === 'primary') || route.firstChild;
  return Object.assign({}, currentParams, mergeRouteParams(primaryChild, getter));
}

function mergeRouteData(route: ActivatedRouteSnapshot): Data {
  if (!route) {
    return {};
  }

  const currentData = route.data;
  const primaryChild = _.find(route.children, c => c.outlet === 'primary') || route.firstChild;
  return Object.assign({}, currentData, mergeRouteData(primaryChild));
}

Even with my custom serializer returning a custom RouterStateUrl interface, the router state type is RouterStateSnapshot and I can't access the params, queryParams and data properties without casting to any.

Version of affected browser(s),operating system(s), npm, node and ngrx:

@ngrx/router-store@4.0.3

Other information:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants