requireState
function requireState(condition: unknown, message?: string): asserts condition;
For the checks that are about the moment rather than the arguments: a connection that is already closed, a sheet that has not been prepared yet, a value that was supposed to be cached by now.
It is declared as a TypeScript assertion, so after the call the compiler treats the condition as true for the rest of the function.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The condition that must hold. |
|
| The message of the exception. A default is used when omitted. |
Returns
asserts condition — nothing; it either passes or throws.
Throws
Exception | Condition |
|---|---|
| the condition is falsy. |
Examples
Guarding a state
function close(connection) {
requireState(connection.isOpen, "The connection is already closed.");
connection.release();
}
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.