From 1992a779b0f8ee525595a6b972563d37700de86c Mon Sep 17 00:00:00 2001 From: bcoll Date: Sun, 10 Sep 2023 21:08:58 +0100 Subject: [PATCH] Fix generated `TextEncoder#encode()` return type --- src/workerd/api/encoding.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/workerd/api/encoding.h b/src/workerd/api/encoding.h index ef6d85e1548..8a820418c2f 100644 --- a/src/workerd/api/encoding.h +++ b/src/workerd/api/encoding.h @@ -220,6 +220,13 @@ class TextEncoder: public jsg::Object { } else { JSG_READONLY_INSTANCE_PROPERTY(encoding, getEncoding); } + + // `encode()` returns `jsg::BufferSource`, which may be an `ArrayBuffer` or `ArrayBufferView`, + // but the implementation uses `jsg::BufferSource::tryAlloc()` which always tries to allocate a + // `Uint8Array`. The spec defines that this function returns a `Uint8Array` too. + JSG_TS_OVERRIDE({ + encode(input?: string): Uint8Array; + }); } };