summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils
diff options
context:
space:
mode:
authorRichie Foreman <[email protected]>2025-08-13 16:17:38 -0400
committerGitHub <[email protected]>2025-08-13 20:17:38 +0000
commita90aeb3d8fd05fc6303ce9ef4e957c2e19cbe9c4 (patch)
tree78423cea4d8f3a3f44d0e182b46fdf0a4bc45de0 /packages/cli/src/utils
parent8fae227e8d53b962f8b7db3abff51906fad1d181 (diff)
chore(build/compiler): Enable a bunch of strict TS compiler options. (#6138)
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);
+}