Conversation
…cket RPC
newWorkersWebSocketRpcResponse is fire-and-forget — it returns a Response but
no handle to the client. For bidirectional use (server calling back to client),
newWorkersWebSocketRpcSession returns { response, remote } where remote is a
typed proxy. On non-upgrade requests it returns a 400 Response with a dead
proxy (dispose/close are no-ops, any other access throws).
newWorkersWebSocketRpcResponse is now a thin wrapper that discards the remote.
Both it and newWebSocketRpcSession share an extracted createRemoteProxy helper,
removing the duplicated Proxy construction.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unify into a single tsconfig.json that covers both library and test files, so the editor/language server picks up Cloudflare Workers types (cloudflare:test) and test type errors are caught by the build. Add npm run typecheck (tsc --noEmit) for quick type checking without emit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- worker.ts: add explicit TLocal type param to newWorkersWebSocketRpcSession - session.test.ts: use double assertion for null-to-RpcProtocolError cast - spec.test.ts: assert response.json() as any for property access - workers.workers.test.ts: fix RpcError constructor args (needs code), use string RpcProtocolErrorCode, assert response.json() as any Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Production code (core.ts): - Replace as-any with Record<string, unknown> casts in isJsonRpcResponse type guard and extractError helper Test code: - Use Object.assign for adding code/data to Error objects - Use JsonRpcResponse[] instead of any[] for processRpc array results - Use proper narrowing (!Array.isArray) instead of as-any in property tests - Use Record<string, unknown> in property test type guard - Add justification comments to remaining 5 as-any usages: 3x Response.json() returns unknown, 1x deliberate type violation, 1x bypassing typed proxy to test dead proxy behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add newWorkersWebSocketRpcSession — new export for bidirectional WebSocket RPC in Workers. Returns { response, remote } so server-side code can call back to the client with a typed proxy. newWorkersWebSocketRpcResponse is now a thin wrapper that discards the remote.
Unify tsconfig — single tsconfig.json covers both library and test files so the editor/language server picks up Cloudflare Workers types. Add npm run typecheck script.
Eliminate as any from production code — replace with Record<string, unknown> casts in type guards. Reduce test as any from 20 to 5 justified instances.
Before/after: bidirectional worker fixture