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/ui/commands/directoryCommand.tsx | 6 ++--- .../src/ui/components/shared/vim-buffer-actions.ts | 3 ++- packages/cli/src/utils/checks.ts | 28 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 packages/cli/src/utils/checks.ts (limited to 'packages/cli/src') diff --git a/packages/cli/src/ui/commands/directoryCommand.tsx b/packages/cli/src/ui/commands/directoryCommand.tsx index 6c667f44..d3f50e4c 100644 --- a/packages/cli/src/ui/commands/directoryCommand.tsx +++ b/packages/cli/src/ui/commands/directoryCommand.tsx @@ -138,13 +138,11 @@ export const directoryCommand: SlashCommand = { if (errors.length > 0) { addItem( - { - type: MessageType.ERROR, - text: errors.join('\n'), - }, + { type: MessageType.ERROR, text: errors.join('\n') }, Date.now(), ); } + return; }, }, { diff --git a/packages/cli/src/ui/components/shared/vim-buffer-actions.ts b/packages/cli/src/ui/components/shared/vim-buffer-actions.ts index 0e2e7989..bf04716f 100644 --- a/packages/cli/src/ui/components/shared/vim-buffer-actions.ts +++ b/packages/cli/src/ui/components/shared/vim-buffer-actions.ts @@ -19,6 +19,7 @@ import { findWordEndInLine, } from './text-buffer.js'; import { cpLen, toCodePoints } from '../../utils/textUtils.js'; +import { assumeExhaustive } from '../../../utils/checks.js'; // Check if we're at the end of a base word (on the last base character) // Returns true if current position has a base character followed only by combining marks until non-word @@ -806,7 +807,7 @@ export function handleVimAction( default: { // This should never happen if TypeScript is working correctly - const _exhaustiveCheck: never = action; + assumeExhaustive(action); return state; } } 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