From d0a3743abdd1aced12fbf08c60015b237e8bc9d1 Mon Sep 17 00:00:00 2001 From: Eric Lytle Date: Mon, 2 Mar 2026 23:31:44 +0000 Subject: [PATCH] refactor: use ??= operator for cleaner globalThis singleton init Addresses greptile review: collapses the if-guard + assignment into a single ??= expression so TypeScript can narrow the type without a non-null assertion. --- src/hooks/internal-hooks.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/internal-hooks.ts b/src/hooks/internal-hooks.ts index 08a642a17e0..fec142b5d54 100644 --- a/src/hooks/internal-hooks.ts +++ b/src/hooks/internal-hooks.ts @@ -213,10 +213,10 @@ export type InternalHookHandler = (event: InternalHookEvent) => Promise | const _g = globalThis as typeof globalThis & { __openclaw_internal_hook_handlers__?: Map; }; -if (!_g.__openclaw_internal_hook_handlers__) { - _g.__openclaw_internal_hook_handlers__ = new Map(); -} -const handlers = _g.__openclaw_internal_hook_handlers__; +const handlers = (_g.__openclaw_internal_hook_handlers__ ??= new Map< + string, + InternalHookHandler[] +>()); const log = createSubsystemLogger("internal-hooks"); /**