porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.03k stars 255 forks source link

TypeScript support for undefined values #855

Closed sambecker closed 1 month ago

sambecker commented 2 months ago

In order to accept undefined in queries, I've applied the following configuration:

export const sql = postgres(process.env.POSTGRES_URL, {
  transform: { undefined: null },
});

But then TypeScript says its usage is not valid:

// TS Error: 'ParameterOrFragment<never>'.ts(2769)
sql`UPDATE table SET field=${undefined} WHERE id=${1}`

Is there a recommended approach to loosen the types?