requireService
function requireService<T>(
service: T | null | undefined,
message: string = "Service is not defined."
): T;
An advanced service that was never enabled is simply an undefined global, and the failure that follows is a ReferenceError far from its cause. This turns it into a named exception with a message that says what to switch on.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The service to check. |
|
| The message of the exception. A default is used when omitted. |
Returns
T — the same service.
Throws
Exception | Condition |
|---|---|
| the service is |
Examples
In use
// An advanced service is a global that only exists once it has been enabled.
const directory = requireService(AdminDirectory, "Enable the Admin SDK service.");
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.