File size: 568 Bytes
d810ed8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/**
* @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);
}
|