apps-script-utils 2.1.1 Help

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

condition

unknown

The condition that must hold.

message (optional)

string

The message of the exception. A default is used when omitted.

Returns

asserts condition — nothing; it either passes or throws.

Throws

Exception

Condition

IllegalStateException

the condition is falsy.

Examples

Guarding a state

function close(connection) { requireState(connection.isOpen, "The connection is already closed."); connection.release(); }

See also

Source

src/lang/base/requireState.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.