ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.01k stars 1.97k forks source link

EntityCollectionService doesn't return typed objects #2624

Closed jonathanschein closed 4 years ago

jonathanschein commented 4 years ago

Minimal reproduction of the bug/regression with instructions:

1) Call a getAll() from a typed EntityCollectionService, for example EntityCollectionService. 2) List all entities stored, and try to use some instance's getter or method

Expected behavior:

All instances should be typed as Hero, but they are untyped.

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

"@ngrx/data": "^9.1.2",
"@ngrx/effects": "^9.1.2",
"@ngrx/entity": "^9.1.2",
"@ngrx/store": "^9.1.2",
"@ngrx/store-devtools": "^9.1.2",

Angular 9.

Other information:

It looks like EntityDataService.getService('hero'), is never called.

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

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

timdeschryver commented 4 years ago

Could you create a reproduction for this @jonathanschein ?

alexkunin commented 4 years ago

@jonathanschein, I'm just guessing here, but maybe you're trying to keep some non-plain objects in entity collection? Apparently that's not intended use for @ngrx/data (and @ngrx/entity -- as a foundation for @ngrx/data), see https://ngrx.io/guide/entity#entity-and-class-instances for details:

S6 class instances will be transformed into plain JavaScript objects when entities are managed in a collection.

As for the following:

All instances should be typed as Hero, but they are untyped.

As far as I can understand, that's just a TypeScript type cast, it means nothing beyond compile-time type checks, i.e. it won't add getters or methods, won't call constructors, etc.

Does this makes sense in the context of your question?

jonathanschein commented 4 years ago

Yes!

That was exactly what he was needing to find out.

Thanks!!!