Skip to content

Commit 62c67ae

Browse files
committed
pg-cloudflare: Workaround typescript bug regarding Buffer.from
Fixes the following error: % yarn build yarn run v1.22.19 $ tsc --build packages/pg-cloudflare/src/index.ts:156:29 - error TS2769: No overload matches this call. The last overload gave the following error. Argument of type 'ArrayBuffer | Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'. Type 'ArrayBuffer' is not assignable to type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'. 156 const hex = Buffer.from(data).toString('hex') ~~~~ node_modules/@types/node/buffer.buffer.d.ts:83:13 83 from( ~~~~~ 84 str: ~~~~~~~~~~~~~~~~~~~~ ... 89 encoding?: BufferEncoding, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 90 ): Buffer<ArrayBuffer>; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The last overload is declared here. Found 1 error. See microsoft/TypeScript#63447 for more info
1 parent 695a7c6 commit 62c67ae

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/pg-cloudflare/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ const debug = false
153153

154154
function dump(data: unknown) {
155155
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
156-
const hex = Buffer.from(data).toString('hex')
156+
// workaround https://github.com/microsoft/TypeScript/issues/63447
157+
const buf = data instanceof Uint8Array ? Buffer.from(data) : Buffer.from(data)
158+
159+
const hex = buf.toString('hex')
157160
const str = new TextDecoder().decode(data)
158161
return `\n>>> STR: "${str.replace(/\n/g, '\\n')}"\n>>> HEX: ${hex}\n`
159162
} else {

0 commit comments

Comments
 (0)