From a90aeb3d8fd05fc6303ce9ef4e957c2e19cbe9c4 Mon Sep 17 00:00:00 2001 From: Richie Foreman Date: Wed, 13 Aug 2025 16:17:38 -0400 Subject: chore(build/compiler): Enable a bunch of strict TS compiler options. (#6138) --- packages/cli/src/utils/checks.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/cli/src/utils/checks.ts (limited to 'packages/cli/src/utils') 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); +} -- cgit v1.2.3