How to return Node.js Buffer
with TypeScript 5.7?
#3700
Unanswered
marvinruder
asked this question in
Q&A
Replies: 2 comments
-
Have you solved it yet? I'm having this problem too! |
Beta Was this translation helpful? Give feedback.
0 replies
-
We should make this an issue in |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The code
runs as expected and shows no errors in TypeScript 5.6, but the following error is shown with TypeScript 5.7:
This is because a
Buffer
is no longer anArrayBuffer
(see https://devblogs.microsoft.com/typescript/announcing-typescript-5-7/#typedarrays-are-now-generic-over-arraybufferlike, microsoft/TypeScript#59417 for details), and theData
type can only be astring
,ArrayBuffer
, orReadableStream
.Returning the
ArrayBuffer
within theBuffer
usingshows no type error, but leads to unexpected results, as responses are 8192 bytes long and contain lots of unrelated data. The reason for this is the shared memory pool from the
Buffer
module:What is the recommended way to use a Node.js
Buffer
as the body of a response? Do Hono’s types need to be updated to conform with the changes in TypeScript 5.7?Beta Was this translation helpful? Give feedback.
All reactions