summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/utils')
-rw-r--r--packages/cli/src/utils/checks.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/cli/src/utils/checks.ts b/packages/cli/src/utils/checks.ts
new file mode 100644
index 00000000..0598835f
--- /dev/null
+++ b/packages/cli/src/utils/checks.ts
@@ -0,0 +1,28 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* Fail to compile on unexpected values. */
+export function assumeExhaustive(_value: never): void {}
+
+/**
+ * Throws an exception on unexpected values.
+ *
+ * A common use case is switch statements:
+ * switch(enumValue) {
+ * case Enum.A:
+ * case Enum.B:
+ * break;
+ * default:
+ * checkExhaustive(enumValue);
+ * }
+ */
+export function checkExhaustive(
+ value: never,
+ msg = `unexpected value ${value}!`,
+): never {
+ assumeExhaustive(value);
+ throw new Error(msg);
+}