は、私は私の効果/店でこのコードを持っている:なぜthis.store.select( "uiState")ngrx /ストアに空のオブジェクトを返す(2.0+)
:@Effect() newMessages$ = Observable.interval(5000)
.withLatestFrom(this.store.select("uiState"))
.map(([unreadMessages, uiState]) => new NewMessagesReceivedAction({
unreadMessages,
currentThreadId: uiState.currentThreadId,
currentUserId: uiState.currentUserId
}))
Webstormはことを私に警告します
Property 'currentThreadId' does not exist on type '{}'.
そしてここでは、私の店ファイルです:
export interface ApplicationState {
uiState: UiState,
storeData: StoreData
}
export const INITIAL_APPLICATION_STATE: ApplicationState = {
uiState: INITIAL_UI_STATE,
storeData: INITIAL_STORE_DATA
}
そして、ここに私のuistateファイルです:
export interface UiState {
userId: string;
currentThreadId: string;
}
export const INITIAL_UI_STATE: UiState = {
userId: undefined,
currentThreadId: undefined
}
誰でも知っていますか?
UPDATE:
@cartant提案した後、私は以下のように)@Effect(のコードを更新し、私は別のWebstorm Typescirptエラーに遭遇:
@Effect() newMessages$ = Observable.interval(5000)
.withLatestFrom(this.store.select<UiState>("uiState"))
.map(([any,uiState]) => uiState)
.filter(uiState => uiState.userId) //Error right here --- As I need to filter out the uiState.userId when there is no userId when the store initialized with undefined value.
.switchMap(uiState => this.threadsService.loadNewMessagesForUser(uiState.userId))
.withLatestFrom(this.store.select<UiState>("uiState"))
.map(([unreadMessages, uiState]) => new NewMessagesReceivedAction({
unreadMessages,
currentThreadId: uiState.currentThreadId,
currentUserId: uiState.userId
}))
Argument of type '(uiState: UiState) => string' is not assignable to parameter of type '(value: UiState, index: number) => boolean'. Type 'string' is not assignable to type 'boolean'.)
私は方法が必要ですFirebaseの呼び出しに未定義またはnullを渡さないように、初期状態または空のuserId状況をフィルタリングします。
は(「uiState」)は、私はまだtypescriptですエラーに遭遇しthis.store.selectあなたのコードを使用してください。なぜ(typescript noobでも)わからない。更新された質問をご覧ください。再度、感謝します! –
'userId'は' string'で、 'filter'は' boolean'の結果を得たいので明示的に '.filter(uiState => Boolean(uiState.userId))'にする必要があります – cartant
フィルタコードは.filter(uiState => {if(uiState.userId){true true;} else {false false}})?私は人々が.filter(uiState => !! uiState.userId)と書いているのを見ました - それは同じことです - userIdが空でないなら、続行してください。それ以外のブレーク操作ですか? –