[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[x] Other... Please describe:
The return of this.query.selectActive(); is typed as Observable<SomeModel[]> | Observable<SomeModel>
I believe it should be typed as Observable<SomeModel[]> only, or at least Observable<SomeModel[] | SomeModel>.
Currently it is
Observable<SomeModel[]> | Observable<SomeModel>
1 - Typescript don't allow to use the .pipe(map(x => ...))
Have to 'cast' to
Observable<any>if want to use the map(this.query.selectActive() as Observable<any>).pipe(map(item => item instanceof Array ? item : [item]));
2 - It's easier to get the first element of array (if only one is allowed)
3 - I believe the Observable is for sure the return type. The doubt here is whether it is an array or not. So, Observable<SomeModel[] | SomeModel> is better (if not Observable<SomeModel[]>).
Angular version: 7.3.0
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
Others:
You need to implement the right interface - ActiveState for single and MultiActiveState for multiple. Please, read the docs. https://netbasal.gitbook.io/akita/entity-store/entity-store/active-state
Advanced comment: Only relevant if generically extending QueryEntity as a helper subclass.
I ran into a related issue when creating my own QueryEntityExtended class that I inherit from. I add various helper functions in here
for example: QueryEntityExtended<...> extends QueryEntity<...>
You can actually cast Observable<E[]> | Observable<E> to Observable<E[] | E> and then run the Array.isArray(...) check within your pipe(...)
So I ended up with:
(this.selectActive() as Observable<E | E[]>).pipe(switchMap(...))
Like I said this is only relevant AFAIK if you're extending the generic class - in which case it won't know what ActiveState you're using. So for most people finding this you probably just need to read the ActiveState docs.
@simeyla wow, I faced the exact problem as yours, and I named my helper class as ExtendedQueryEntity lol. so lucky to find your answer here, after several hours in the problem...
Most helpful comment
You need to implement the right interface -
ActiveStatefor single andMultiActiveStatefor multiple. Please, read the docs. https://netbasal.gitbook.io/akita/entity-store/entity-store/active-state