Skip to content

fix(pg-protocol): add explicit return types to serializers to be compatible with older versions of @types/node - #3848

Open
dax-side wants to merge 1 commit into
brianc:masterfrom
dax-side:fix-3699-buffer-typings
Open

dax-side wants to merge 1 commit into
brianc:masterfrom
dax-side:fix-3699-buffer-typings

Conversation

@dax-side

@dax-side dax-side commented Nov 4, 2026

Copy link
Copy Markdown

closes #3699

Currently the serializer.d.ts that gets published with pg-protocol 1.16.1 types flush, sync, end and copyDone as returning Buffer<ArrayBufferLike>. These are the only 4 functions in the serializer that dont have an explicit return type so the types file will generate whatever your current version of @types/node produces. This will cause TS2315: Type 'Buffer' is not generic when trying to import pg on a project that uses an older version of @types/node where Buffer is not generic.

This will type those 4 functions as returning : Buffer similar to all the other functions in serializer.ts. So that the .d.ts file will output Buffer no matter what version of @types/node you have installed when building. There is no change at runtime.

Also added a test to outbound-serializer.test.ts that verifies the serializer.d.ts file does not contain Buffer<. Currently this test will pass with our lock file using @types/node@16 both before and after this change. But it should detect this issue in the future if someone builds with a newer version of @types/node such as when #3801 gets merged. If you dont want the test I can remove it

…th 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<ArrayBufferLike>, 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 brianc#3699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure on a project running on TS 4.7.4

1 participant