Skip to content

Commit 2384f6c

Browse files
committed
ensure nulls arent passed to sort
1 parent ab3b69f commit 2384f6c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

frontend/src/components/AnnouncementsDisplay.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ export function AnnouncementsDisplay() {
3838
setAnnouncements((oldAnnouncements) => {
3939
const newArr = [...oldAnnouncements, ...newAnnouncements];
4040
const setOfIds = new Set(newArr.map((a) => a.id));
41-
return Array.from(setOfIds)
42-
.map((id) => newArr.find((a) => a.id === id)!)
43-
.sort((a, b) => {
41+
return (
42+
(
43+
Array.from(setOfIds)
44+
.map((id) => newArr.find((a) => a.id === id))
45+
// Typescript doesn't type filter(Boolean) correctly, so I have to assert this
46+
.filter(Boolean) as Announcement[]
47+
).sort((a, b) => {
4448
return new Date(b.created).getTime() - new Date(a.created).getTime();
45-
});
49+
})
50+
);
4651
});
4752
}
4853

0 commit comments

Comments
 (0)