Skip to content

Conversation

SebastienGllmt
Copy link
Contributor

@SebastienGllmt SebastienGllmt commented Apr 29, 2025

Buffer is not a global type inherent to Typescript (comes from nodejs) so not all compiler options support it. Therefore, using pgtyped in those environments can lead to a compiler error on the Buffer type

Tools usually solve this with two options:

  1. Mock out the node:buffer module (so import type { Buffer } from "node:buffer"; works)
  2. Add Buffer to the global namespace

Adding to the global namespace is generally bad, so option (1) is usually preferred. However, pgtyped only supported option (2)

This PR changes so files generated from pgtyped include import type { Buffer } from 'node:buffer'; in the generated code so that projects using pgtyped don't have to pollute their global namespace to get the project working. This reduces the need for hacks like #262 (comment)

Copy link

vercel bot commented Apr 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pgtyped ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2025 9:14am

definition: 'Date | string',
};
const Bytes: Type = { name: 'Buffer' };
const Bytes: Type = { name: 'Buffer', from: 'node:buffer' };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, this whole PR is just a single line (everything else is tests)

@SebastienGllmt SebastienGllmt mentioned this pull request May 1, 2025
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.

1 participant