← Back to Pull requests

types: declare bytes() and TextEncoderStream output as Uint8Array<ArrayBuffer> #9016

Open
unknown opened this pull request with 193 lines diff across 2 files
View on GitHub
unknown unknown commented on Dec 04, 2026 00:23 UTC
Author

Follow-up to #8996, as suggested in its review.

Blob.bytes(), Body.bytes() (so Request and Response), R2ObjectBody.bytes() and the chunks TextEncoderStream emits are all views over fresh, non-shared ArrayBuffers, but they were declared with the bare Uint8Array. Since TypeScript 5.7 that means Uint8Array<ArrayBufferLike>, which includes SharedArrayBuffer, so passing the result where a Uint8Array<ArrayBuffer> (or a BufferSource that rejects shared memory) is expected fails with TS2322/TS2345. TypeScript's own lib.dom.d.ts declares these as Uint8Array<ArrayBuffer>.

Changes

  • src/workerd/api/blob.h, http.h, r2-bucket.h: bytes(): Promise<Uint8Array<ArrayBuffer>> in the JSG_TS_OVERRIDEs.

  • src/workerd/api/streams/encoding.h: TextEncoderStream extends TransformStream<string, Uint8Array<ArrayBuffer>>.

  • types/generated-snapshot/: the matching changes in the four snapshot files.

  • types/test/types/bytes.ts: a type test for the four bytes() methods, .buffer being an ArrayBuffer, and TextEncoderStream's readable/writable.
  • As noted on #8996, this keeps TypeScript 5.7 as the minimum for these declarations.

    Testing

    With TypeScript 6.0.3 (the repo's version), the new type test passes against both updated snapshots and fails with TS2345 on every assertion against the current ones. As in #8996, I could not run just generate-types locally (Windows), so the snapshot lines were updated by hand and checked against Prettier's output; CI's check-snapshot will confirm them.

    Diff: 193 lines (+144 / -49) across 2 files Reviewer: petebacondarwin Review duration: 1344m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.36) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 193 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.315
    Real PR Conversation Timeline
    1 comments
    "Review active on #9016"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.0% (MEDIUM) · Higher = larger blast radius
    36.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%