mirror of
https://github.com/status-im/nimbus-gui.git
synced 2025-02-27 18:40:33 +00:00
feat(dev): add assertUnreachable
Asserts that a case is unreachable in `switch` statements (and really any flow control construct)
This commit is contained in:
parent
f36bf56a6a
commit
41e24a1e4f
18
src/utilities.ts
Normal file
18
src/utilities.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Asserts that a case in a switch statement is unreachable.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Exhaustively checks `user.role` type ("admin" | "user") and will not compile
|
||||||
|
* // if a new role is added without adding a case to the switch statement.
|
||||||
|
* switch (user.role) {
|
||||||
|
* case "admin":
|
||||||
|
* break;
|
||||||
|
* case "user":
|
||||||
|
* break;
|
||||||
|
* default:
|
||||||
|
* assertUnreachable(user.role);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export function assertUnreachable(value: never): never {
|
||||||
|
throw new Error(`Unreachable case: ${value}`);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user