porsager / postgres

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

No overload matches this call #685

Closed dinogomez closed 11 months ago

dinogomez commented 11 months ago
const user = {
    firstName: firstName,
    lastName: lastName,
    userName: userName,
    password: hashedPassword,
};
const columns = ["firstName", "lastName", "userName", "password"];

const res = await sql`insert into users ${sql(user, columns)}`; //error on "${sql(user, columns)}"

This code gives a No overload matches this call

No overload matches this call.
  Argument of type '[Helper<{ firstName: any; lastName: any; userName: any; password: any; }, readonly ("firstName" | "lastName" | "userName" | "password")[]>]' is not assignable to parameter of type 'never'.
  Overload 2 of 2, '(template: TemplateStringsArray, ...parameters: readonly ParameterOrFragment<never>[]): PendingQuery<Row[]>', gave the following error.
    Argument of type 'Helper<{ firstName: any; lastName: any; userName: any; password: any; }, readonly ("firstName" | "lastName" | "userName" | "password")[]>' is not assignable to parameter of type 'ParameterOrFragment<never>'.
      Type 'Helper<{ firstName: any; lastName: any; userName: any; password: any; }, readonly ("firstName" | "lastName" | "userName" | "password")[]>' is not assignable to type 'Helper<any, any[]>'.
        The type 'readonly ("firstName" | "lastName" | "userName" | "password")[]' is 'readonly' and cannot be assigned to the mutable type 'any[]'.ts(2769)
No overload matches this call.
  Overload 1 of 2, '(first: { firstName: any; lastName: any; userName: any; password: any; }, ...rest: readonly ("firstName" | "lastName" | "userName" | "password")[]): Helper<{ firstName: any; lastName: any; userName: any; password: any; }, readonly ("firstName" | ... 2 more ... | "password")[]>', gave the following error.
    Argument of type 'string[]' is not assignable to parameter of type '"firstName" | "lastName" | "userName" | "password"'.
  Overload 2 of 2, '(template: TemplateStringsArray, ...parameters: readonly ParameterOrFragment<never>[]): PendingQuery<Row[]>', gave the following error.
    Argument of type '{ firstName: any; lastName: any; userName: any; password: any; }' is not assignable to parameter of type 'TemplateStringsArray'.
      Type '{ firstName: any; lastName: any; userName: any; password: any; }' is missing the following properties from type 'TemplateStringsArray': raw, length, concat, join, and 27 more.ts(2769)
const user: {
    firstName: any;
    lastName: any;
    userName: any;
    password: any;
}

The code above still works though and will still insert into the database. image

Kinda confused on how to proceed, following the guide here in dynamic inserts on the docs.

alpharder commented 11 months ago

Will be fixed by https://github.com/porsager/postgres/pull/679

alpharder commented 11 months ago

@dinogomez Please confirm the latest release resolves your problem and consider closing the issue if so.

dinogomez commented 11 months ago

@alpharder On updating to 3.4.0, can confirm typescript errors on overload are handled. Thank you for the hard work 💙