2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-02-01 18:57:31 -06:00
|
|
|
import { reallyJsonStringify } from './reallyJsonStringify';
|
2020-11-12 12:09:39 -06:00
|
|
|
|
2018-04-12 17:19:13 -04:00
|
|
|
// `missingCaseError` is useful for compile-time checking that all `case`s in
|
|
|
|
// a `switch` statement have been handled, e.g.
|
|
|
|
//
|
|
|
|
// type AttachmentType = 'media' | 'documents';
|
|
|
|
//
|
|
|
|
// const type: AttachmentType = selectedTab;
|
|
|
|
// switch (type) {
|
|
|
|
// case 'media':
|
2018-04-14 21:11:40 -04:00
|
|
|
// return <MediaGridItem/>;
|
2018-04-12 17:19:13 -04:00
|
|
|
// case 'documents':
|
2018-04-14 21:11:40 -04:00
|
|
|
// return <DocumentListItem/>;
|
2018-04-12 17:19:13 -04:00
|
|
|
// default:
|
|
|
|
// return missingCaseError(type);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If we extended `AttachmentType` to `'media' | 'documents' | 'links'` the code
|
|
|
|
// above would trigger a compiler error stating that `'links'` has not been
|
|
|
|
// handled by our `switch` / `case` statement which is useful for code
|
|
|
|
// maintenance and system evolution.
|
|
|
|
export const missingCaseError = (x: never): TypeError =>
|
2022-02-01 18:57:31 -06:00
|
|
|
new TypeError(`Unhandled case: ${reallyJsonStringify(x)}`);
|