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

Incorrect typings on router-state selectors #2516

Closed
Brachacz opened this issue May 6, 2020 · 2 comments · Fixed by #2517
Closed

Incorrect typings on router-state selectors #2516

Brachacz opened this issue May 6, 2020 · 2 comments · Fixed by #2517

Comments

@Brachacz
Copy link

Brachacz commented May 6, 2020

9.1.1 (more specifically 39a4b91) introduced regression.

selectQueryParam, selectRouteParams, selectRouteParam, selectRouteData, selectUrl selectors now seem to be factory functions that return selectors.
While that is correct for selectQueryParam and selectRouteParam, all of them expose additional (state: V) => layer that actually is part of MemoizedSelector.

This breaks typings selector usages and makes TypeScript think that, for example selectUrl returns a MemoizedSelector and not just string.
Functionality remains functional, only thing broken is the https://github.com/ngrx/platform/blob/master/modules/router-store/src/models.ts interface.

Long story short (state: V) => MemoizedSelector<V, whatever> selectors should be just MemoizedSelector<V, whatever>.

Entity selectors are probably similarly affected.

Expected behavior:

It should be possible to use selectUrl in createSelector and expect returned value to be a string without having to do workarounds like:

export const selectIsProfileRouteActive = createSelector(
  AppSelectors.selectUrl as any,
  (url: string) => url === USER_PROFILE_ROUTE.url
);

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

ngrx: 9.1.1
Angular: 9.1.4
Node: 14.0.0

I would be willing to submit a PR to fix this issue

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@Flyrell
Copy link

Flyrell commented May 6, 2020

My versions of node/angular are the exact same and I'm also experiencing the issue, quick fix would be to downgrade the @ngrx/* packages to 9.1.0

I believe this is the pull request that has changed the return value types of the selectors in order to make them "mockable".

@brandonroberts
Copy link
Member

We are looking into the typings issue. The PR unintentionally broke the types, so we reverted it and released 9.1.2

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

Successfully merging a pull request may close this issue.

3 participants