A recent project of mine involves using NGXS in an Angular setup.
Within my AuthState, I have the following code snippet:
@Injectable()
export class AuthState {
@Selector()
static isAuthenticated(state: AuthStateModel) {
return state.currentUser !== null;
}
//...
}
When implementing this in a component, I encountered an issue:
export class HeaderComponent implements OnInit {
@Select(AuthState.isAuthenticated) isAuthenticated$: Observable<boolean>;
//...
}
Unfortunately, this resulted in a compilation error:
src/app/layout/header/header.component.ts:14:38 - error TS2564: Property 'isAuthenticated$' has no initializer and is not definitely assigned in the constructor.
14 @Select(AuthState.isAuthenticated) isAuthenticated$: Observable<boolean>;
~~~~~~~~~~~~~~~~
I understand why Angular is facing this problem, as it cannot ensure proper initialization upfront.
After researching a bit, I came across suggestions to disable property initialization checks by adding the following line to the tsconfig file:
"strictPropertyInitialization": false
However, I prefer to keep this check enabled for better development practices. Is there a way to address this issue without disabling it application-wide while still utilizing NGXS Select feature?