Nx: Failing to use Selectors Composition

Created on 1 Oct 2019  路  3Comments  路  Source: nrwl/nx

  • [X] I am running the latest version
  • [X] I checked the documentation and found no answer
  • [X] I checked to make sure that this issue has not already been filed
  • [ ] I'm reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

I am expecting to be able to compose selectors form multiple data-access libs from two or more other data libs

Current Behavior

I am currently getting an error in the createSelectors about No overload matches this call.

Failure Information (for bugs)

Screenshot 2019-10-01 at 11 33 38

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. I created an empty nrwl workspace
  2. Created two feature libs and two data-access libs (airplanes-feature-shell, airplanes-data-access, categories-feature-shell, categories-data-access)
  3. I then imported the airplanes-data-access module into the categories-data-access lib.
  4. I then imported getAllAirplanes selector from airplanes-data-access lib.
  5. created new selector with getAllCategories and getAllAirplanes.

online repo: Stackblitz

Context

Please provide any relevant information about your setup:

  • version of Nx used 8.5.2

Failure Logs

Screenshot 2019-10-01 at 11 40 10

angular bug

Most helpful comment

The getCategoriesState is restricted to the CategoriesPartialState by default, so you can do what @mhamel06 mentioned above or:

export const getCategoriesState = createFeatureSelector<
  CategoriesPartialState & AirplanesPartialState,
  State
>(CATEGORIES_FEATURE_KEY);

Then your types will flow correctly.

All 3 comments

It's pretty verbose, but would something like this work for now?

// Tell create selector to expect a partial state with both Airplane and Category features
export const getAllCategoriesWithAirplanes = createSelector<
  CategoriesPartialState & AirplanesPartialState,
  CategoriesEntity[],
  AirplanesEntity[],
  any[]
  >(
  getAllCategories,
  getAllAirplanes,
  (categories, airplanes) => {
    return [];
  }
);

The getCategoriesState is restricted to the CategoriesPartialState by default, so you can do what @mhamel06 mentioned above or:

export const getCategoriesState = createFeatureSelector<
  CategoriesPartialState & AirplanesPartialState,
  State
>(CATEGORIES_FEATURE_KEY);

Then your types will flow correctly.

Thank you works like a charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

about-code picture about-code  路  3Comments

zachnewburgh picture zachnewburgh  路  3Comments

jasedwards picture jasedwards  路  3Comments

jon301 picture jon301  路  3Comments

MichaelWarneke picture MichaelWarneke  路  3Comments