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; + }); } };