store icon indicating copy to clipboard operation
store copied to clipboard

Angular Store select error: no initializer message after updating to Angular 5

Open UrielMhezzek opened this issue 7 years ago • 2 comments

This is a...

  • [ ] feature request
  • [ ] bug report
  • [x ] usage question

What toolchain are you using for transpilation/bundling?

  • [ x] @angular/cli
  • [ ] Custom @ngTools/webpack
  • [ ] Raw ngc
  • [ ] SystemJS
  • [ ] Rollup
  • [ ] Other

Environment

NodeJS Version: 8.2.1 Typescript Version: 2.7.1 Angular Version: 5.2.4 @angular-redux/store version: 7.1.0 @angular/cli version: (if applicable) 1.2.6 OS: Windows 10 64 Bit

Link to repo showing the issus

(optional, but helps a lot) I use the Angular Store in my app. After updating from Angular 4 to 5, I always get the following message when querying a variable

TS2564: Property' messages' has no initializer and is not definitely assigned in the constructor.

For example, with this property

@select ([' messagelist',' messages']]) readonly messages: Observable<Message[]>; Before the update I used the following line of code

@select (s => s. messagelist. messages) messages: Message[] =[]; Here is the top level of my store

export interface IAppState {
   identity: IIdentityState;
   messagelist: IMessagelistState;
   settings: ISettingsState;
}

export const INITIAL_STATE: IAppState = {
   identity: IDENTITY_INITIAL_STATE,
   messagelist: MESSAGELIST_INITIAL_STATE,
   settings: SETTINGS_INITIAL_STATE,
}



export const rootReducer = composeReducers(
   defaultFormReducer(),
   combineReducers({
       messagelist: messageListReducer,
       identity: identityReducer,
       settings: settingsReducer
  })
);

Here is the lowest level of my stores

export interface IMessagelistState {
    messages: Message[];
    ids: number;
}

export const MESSAGELIST_INITIAL_STATE: IMessagelistState = {
    messages: [],
    ids: 0
}

Expected Behaviour:

No error message

Actual Behaviour:

Error Message ERROR in [at-loader] ./ClientApp/app/components/messagelist/messagelist.component.ts:16:46

Stack Trace/Error Message:

Additional Notes:

(optional)

UrielMhezzek avatar Feb 20 '18 20:02 UrielMhezzek

I experimented around and found a workaround.

export class MessageListComponent {
    messages: Observable<Message[]> = new Observable<Message[]>();

    constructor(private ngRedux: NgRedux<IAppState>) {
        this.messages = ngRedux.select(['messagelist', 'messages']);
    }
}

UrielMhezzek avatar Feb 26 '18 20:02 UrielMhezzek

The root cause ist the Typescript update to 2.7.1 which added new checks, you can get the old behavior if you set

"strictPropertyInitialization": false

in tsconfig.json.

DcsMarcRemolt avatar Apr 13 '18 09:04 DcsMarcRemolt