Workers SDK Issue Reports

← Back to Dashboard

#8566 Missing dispose on RPC Stub promise type

Recommendation:KEEP OPEN
Difficulty:medium
Reasoning:

TypeScript type bug: RPC stub promises lack Disposable interface for `using` declaration. Internal tests have TODO comments acknowledging this. No PRs fix it.

Suggested Action:

Update RPC types to include Disposable on stub promise types (may be in @cloudflare/workers-types)

Analysis Report

Issue #8566: Missing dispose on RPC Stub promise type

Summary

Field Value
Issue #8566
Title Missing dispose on RPC Stub promise type
State OPEN
Created 2025-03-19
Updated 2025-10-30
Labels bug
Reporter Version wrangler 4.1.0
Current Version wrangler 4.60.0

Problem Description

The RPC Stub promise type does not include the Disposable interface, which prevents using the using declaration with non-awaited RPC calls (pipelining pattern).

Working code (awaited):

using result = await worker.foo()
using m = await result.method()

Failing code (pipelined):

using result2 = worker.foo()      // TS2850: No [Symbol.dispose]() method
using m2 = result2.method()       // TS2850: No [Symbol.dispose]() method

Analysis

Evidence the Issue Still Exists

  1. No PRs found mentioning issue #8566

  2. No commits found referencing this issue

  3. No changelog entries for fixing dispose types on RPC stubs

  4. Internal test code confirms the problem: The workers-sdk test file at fixtures/vitest-pool-workers-examples/rpc/test/unit.test.ts contains:

    // TODO: Improve RPC types so this casting isn't required
    using counter2 = (await result.clone()) as unknown as Counter & Disposable;
    

    This TODO comment acknowledges the typing issue exists and requires a workaround.

  5. Another test workaround in the same file:

    // TODO(soon): replace with `using` when supported
    onTestFinished(() => stub[Symbol.dispose]());
    

Root Cause

This is a TypeScript type definition issue. The RPC pipelining feature returns a Promise-like object that is also Disposable at runtime, but the type definitions don't reflect this. When you don't await the RPC call, TypeScript doesn't know the return type implements Disposable.

User Impact

  • Developers must either await each RPC call (losing pipelining benefits) or use workarounds like as unknown as T & Disposable casting
  • The workaround mentioned by the reporter is to use any type

Reproduction

The reporter provided a minimal reproduction at https://github.com/xlc/using-issue which demonstrates the issue.

Recommendation

KEEP OPEN - This is a valid, unresolved TypeScript typing bug. The issue has active community interest (2 comments asking for workarounds) and is acknowledged in the workers-sdk test code with TODO comments indicating a fix is needed.

Additional Notes

  • This is a type-only issue; the runtime behavior works correctly
  • The fix would involve updating the type definitions to include Disposable on the RPC stub promise types
  • The types may be defined in @cloudflare/workers-types (separate repo) rather than workers-sdk

Notes & Feedback (0)

No notes yet.

Add Note