From 867d1ac647b9b063626b3b24fc92e35df559e282 Mon Sep 17 00:00:00 2001 From: Damola Adegbite <101389494+dax-side@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:22:13 +0000 Subject: [PATCH] fix(pg-protocol): annotate serializer return types so typings work with older @types/node flush, sync, end and copyDone had inferred return types. When the package is built against a recent @types/node, the declaration emitter writes them as Buffer, and projects on an older @types/node (where Buffer is not generic) fail with TS2315 just by importing pg. Annotating them as Buffer, like the other serializer functions, makes the emitted .d.ts plain Buffer whatever @types/node the build uses. Fixes #3699 --- packages/pg-protocol/src/outbound-serializer.test.ts | 8 ++++++++ packages/pg-protocol/src/serializer.ts | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/pg-protocol/src/outbound-serializer.test.ts b/packages/pg-protocol/src/outbound-serializer.test.ts index aac0c57ba..9337c0471 100644 --- a/packages/pg-protocol/src/outbound-serializer.test.ts +++ b/packages/pg-protocol/src/outbound-serializer.test.ts @@ -1,4 +1,6 @@ import assert from 'assert' +import fs from 'fs' +import path from 'path' import { serialize } from './serializer' import BufferList from './testing/buffer-list' @@ -24,6 +26,12 @@ describe('serializer', () => { ) }) + it('emits declarations that do not need a generic Buffer', function () { + // older @types/node releases declare a non-generic Buffer; see #3699 + const declarations = fs.readFileSync(path.join(__dirname, 'serializer.d.ts'), 'utf8') + assert.ok(!declarations.includes('Buffer<'), declarations) + }) + it('builds password message', function () { const actual = serialize.password('!') assert.deepEqual(actual, new BufferList().addCString('!').join(true, 'p')) diff --git a/packages/pg-protocol/src/serializer.ts b/packages/pg-protocol/src/serializer.ts index bbd59623e..651c4bffa 100644 --- a/packages/pg-protocol/src/serializer.ts +++ b/packages/pg-protocol/src/serializer.ts @@ -274,11 +274,11 @@ const serialize = { execute, describe, close, - flush: () => flushBuffer, - sync: () => syncBuffer, - end: () => endBuffer, + flush: (): Buffer => flushBuffer, + sync: (): Buffer => syncBuffer, + end: (): Buffer => endBuffer, copyData, - copyDone: () => copyDoneBuffer, + copyDone: (): Buffer => copyDoneBuffer, copyFail, cancel, }