Skip to content

Commit 861b0cb

Browse files
alex-okrushkobrandonroberts
authored andcommitted
fix(example): handle possible undefined results from Dictionary (#1745)
Closes #1735
1 parent db5c141 commit 861b0cb

File tree

1 file changed

+7
-2
lines changed
  • projects/example-app/src/app/books/reducers

1 file changed

+7
-2
lines changed

projects/example-app/src/app/books/reducers/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as fromSearch from '@example-app/books/reducers/search.reducer';
77
import * as fromBooks from '@example-app/books/reducers/books.reducer';
88
import * as fromCollection from '@example-app/books/reducers/collection.reducer';
99
import * as fromRoot from '@example-app/reducers';
10+
import { Book } from '../models/book';
1011

1112
export interface BooksState {
1213
search: fromSearch.State;
@@ -122,7 +123,9 @@ export const getSearchResults = createSelector(
122123
getBookEntities,
123124
getSearchBookIds,
124125
(books, searchIds) => {
125-
return searchIds.map(id => books[id]);
126+
return searchIds
127+
.map(id => books[id])
128+
.filter((book): book is Book => book != null);
126129
}
127130
);
128131

@@ -148,7 +151,9 @@ export const getBookCollection = createSelector(
148151
getBookEntities,
149152
getCollectionBookIds,
150153
(entities, ids) => {
151-
return ids.map(id => entities[id]);
154+
return ids
155+
.map(id => entities[id])
156+
.filter((book): book is Book => book != null);
152157
}
153158
);
154159

0 commit comments

Comments
 (0)