1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
5 * A utility function for exhaustive checks in switch statements.
7 * If a switch statement should handle all possible cases of a union type,
8 * you can use this function in the `default` case. TypeScript will ensure
9 * that the type of the variable passed to this function is `never`, meaning
10 * all other cases have been exhausted. If you add a new type to the union
11 * and forget to handle it in the switch, the compiler will raise an error
12 * at the call site of this function.
14 * @param x - The variable that should be of type `never`.
15 * @returns This function never returns; it throws an error.
17export function assertNever(x: never): never {
18 throw new Error(`Unexpected object: ${JSON.stringify(x)}`);
22 * Creates a new object by omitting specified keys from an existing object.
23 * This is a type-safe alternative to using destructuring with rest syntax
24 * when trying to avoid `no-unused-vars` linting errors.
26 * @param obj The source object.
27 * @param keys The keys to omit from the new object.
28 * @returns A new object without the specified keys.
30export function omit<T extends Record<string, unknown>, K extends keyof T>(
34 const ret = { ...obj };
35 for (const key of keys) {