Store: 馃悶[BUG]: Cannot assign @Select to private property

Created on 10 Feb 2020  路  15Comments  路  Source: ngxs/store

Affected Package


The issue is caused by package @ngxs/5.6.2

Is this a regression?


Yes, it worked just fine in 3.4.3

Description

A clear and concise description of the problem...
Using the @Select decorator to assign to private properties of another class results in this error:

Argument of type 'HelloComponent' is not assignable to parameter of type 'ComponentClass<any> & Record<"_name", Observable<string>>'.
  Type 'HelloComponent' is not assignable to type 'Record<"_name", Observable<string>>'.
    Property '_name' is private in type 'HelloComponent' but not in type 'Record<"_name", Observable<string>>'.

馃敩 Minimal Reproduction



https://stackblitz.com/edit/ngxs-at-select-private-property?file=src%2Fapp%2Fhello.component.ts

Environment


Libs:

  • @angular/core version: 8.2.4
  • @ngxs/store version: 5.6.2
  • Typescript version: 3.7.5
core high bufix

Most helpful comment

Good news this has been addressed in NGXS v3.7, released last week.
( see https://dev.to/ngxs/announcing-ngxs-3-7-1kbk for release notes )

I will close this issue. Please let us know if it is not resolved.

All 15 comments

please create stackblitz or guthub repo with reproduce

There is a link under "Minimal reproduction"... IDK why it won't make it an actual link..

@splincode I believe that this would have been caused by the extra typings you added in this commit:
https://github.com/ngxs/store/commit/ca7de82b3032057743dbd1cb4e50a5cf934011d1#diff-f51f5a2731644ac6eec21012cd378ad6R14
Are you able to improve the types to handle private fields?

Sorry, I read the description poorly and did not look at the link

Sorry, I read the description poorly and did not look at the link.

@markwhitfeld I will investigate

I'm getting this issue as well. In our case we have an AbstractAuthorityGuard which has a "default" implementation of CanActivate and allows for other Guards to extend the abstract class and do minor additional checks. Sort of like this oversimplified example:

@Injectable({
    providedIn: 'root'
})
export abstract class AbstractAuthorityGuard implements CanActivate {
    @Select(SessionState.authorities)
    protected authorities$: Observable<UserAuthority[]>;

    canActivate(): Observable<boolean> {
        return this.authorities$;
    }
}

This is happening after upgrading to Angular 9, TypeScript 3.7.5 and @ngxs/[email protected].

Hey guys, any update on this? :)

While this is a difficult time, I will get to this problem soon

I have now completely concentrated my efforts on a new plugin that will improve working with states:
https://github.com/ngxs-labs/data

Thanks for the update! ngxs-labs/data looks very promising! Is there a release planned for the near future?

It is planned to implement a lot of functionality yet, but I hope to make a release at the end of this month

Any update? I've got a large codebase that I'd like to upgrade to Angular 9, but this issue is blocking.

It looks like @splincode is working on this in PR #1623. Hope to get this fix into the next release!

It looks like you guys have merged the PR already. Is there anything more that needs to be done for this to get released? :)

Off-topic: How are things going with ngxs-labs/data?

Good news this has been addressed in NGXS v3.7, released last week.
( see https://dev.to/ngxs/announcing-ngxs-3-7-1kbk for release notes )

I will close this issue. Please let us know if it is not resolved.

Awesome news! Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings