From 8e0b94e720413faac03501a0184f7a54f2db1500 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Thu, 2 Sep 2021 12:43:56 -0500 Subject: [PATCH] Use `missingCaseError` in `groupMediaItemsByDate` --- .../media-gallery/groupMediaItemsByDate.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/ts/components/conversation/media-gallery/groupMediaItemsByDate.ts b/ts/components/conversation/media-gallery/groupMediaItemsByDate.ts index 214a5f8637..dce498b4b1 100644 --- a/ts/components/conversation/media-gallery/groupMediaItemsByDate.ts +++ b/ts/components/conversation/media-gallery/groupMediaItemsByDate.ts @@ -4,10 +4,11 @@ import moment from 'moment'; import { compact, groupBy, sortBy } from 'lodash'; +import * as log from '../../../logging/log'; import { MediaItemType } from '../../../types/MediaItem'; import { getMessageTimestamp } from '../../../util/getMessageTimestamp'; -// import { missingCaseError } from '../../../util/missingCaseError'; +import { missingCaseError } from '../../../util/missingCaseError'; type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth'; type YearMonthSectionType = 'yearMonth'; @@ -54,13 +55,13 @@ const toSection = ( messagesWithSection: Array | undefined ): Section | undefined => { if (!messagesWithSection || messagesWithSection.length === 0) { - return; + return undefined; } - const firstMediaItemWithSection: MediaItemWithSection = + const firstMediaItemWithSection: undefined | MediaItemWithSection = messagesWithSection[0]; if (!firstMediaItemWithSection) { - return; + return undefined; } const mediaItems = messagesWithSection.map( @@ -71,13 +72,11 @@ const toSection = ( case 'yesterday': case 'thisWeek': case 'thisMonth': - // eslint-disable-next-line consistent-return return { type: firstMediaItemWithSection.type, mediaItems, }; case 'yearMonth': - // eslint-disable-next-line consistent-return return { type: firstMediaItemWithSection.type, year: firstMediaItemWithSection.year, @@ -85,12 +84,8 @@ const toSection = ( mediaItems, }; default: - // NOTE: Investigate why we get the following error: - // error TS2345: Argument of type 'any' is not assignable to parameter - // of type 'never'. - // return missingCaseError(firstMediaItemWithSection.type); - // eslint-disable-next-line no-useless-return - return; + log.error(missingCaseError(firstMediaItemWithSection)); + return undefined; } };