diff --git a/types/defines/rpc.d.ts b/types/defines/rpc.d.ts index cba6f1d6e7e..724870f48f5 100644 --- a/types/defines/rpc.d.ts +++ b/types/defines/rpc.d.ts @@ -190,7 +190,7 @@ declare module "cloudflare:workers" { constructor(ctx: DurableObjectState, env: Env); fetch?(request: Request): Response | Promise; - alarm?(): void | Promise; + alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise; webSocketMessage?( ws: WebSocket, message: string | ArrayBuffer diff --git a/types/test/types/rpc.ts b/types/test/types/rpc.ts index 4307bb94692..a77a553ae87 100644 --- a/types/test/types/rpc.ts +++ b/types/test/types/rpc.ts @@ -306,6 +306,27 @@ class TestObject extends DurableObject { } } +class TestAlarmObject extends DurableObject { + // Can declare alarm method consuming optional alarmInfo parameter + async alarm(alarmInfo?: AlarmInvocationInfo) { + if (alarmInfo !== undefined) { + const _isRetry: boolean = alarmInfo.isRetry; + const _retryCount: number = alarmInfo.retryCount; + } + } + + // User code can invoke alarm() directly, if desired. + async runAlarmVoid(): Promise { + return await this.alarm(); + } + async runAlarmInfo(): Promise { + return await this.alarm({ + isRetry: true, + retryCount: 1, + }); + } +} + class TestNaughtyEntrypoint extends WorkerEntrypoint { // Check incorrectly typed methods // @ts-expect-error @@ -351,6 +372,7 @@ interface Env { REGULAR_OBJECT: DurableObjectNamespace; RPC_OBJECT: DurableObjectNamespace; + ALARM_OBJECT: DurableObjectNamespace; NAUGHTY_OBJECT: DurableObjectNamespace; // @ts-expect-error `BoringClass` isn't an RPC capable type __INVALID_OBJECT_1: DurableObjectNamespace;