Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(example): handle possible undefined results from Dictionary #1745

Merged
merged 1 commit into from
Apr 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions projects/example-app/src/app/books/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as fromSearch from '@example-app/books/reducers/search.reducer';
import * as fromBooks from '@example-app/books/reducers/books.reducer';
import * as fromCollection from '@example-app/books/reducers/collection.reducer';
import * as fromRoot from '@example-app/reducers';
import { Book } from '../models/book';

export interface BooksState {
search: fromSearch.State;
Expand Down Expand Up @@ -122,7 +123,9 @@ export const getSearchResults = createSelector(
getBookEntities,
getSearchBookIds,
(books, searchIds) => {
return searchIds.map(id => books[id]);
return searchIds
.map(id => books[id])
.filter((book): book is Book => book != null);
Copy link
Member

@brandonroberts brandonroberts Apr 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use .filter(Boolean)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.filter(Boolean) doesn't work with strictNullChecks
PLAYGROUND LINK

Screen Shot 2019-04-13 at 3 56 03 PM

}
);

Expand All @@ -148,7 +151,9 @@ export const getBookCollection = createSelector(
getBookEntities,
getCollectionBookIds,
(entities, ids) => {
return ids.map(id => entities[id]);
return ids
.map(id => entities[id])
.filter((book): book is Book => book != null);
}
);

Expand Down