porsager / porsager/postgres

No overload matches this call

Open
#916 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

The following snippet is generating an error:

import client from "./driver";

export interface Course {
    id?: number;
    name: string;
    description: string;
    price: number;
    image: string;
}

export interface UpdateCourse {
    name?: string;
    description?: string;
    price?: number;
    image?: string;
}

export const updateCourse = async (id: number, course: UpdateCourse) => {
    // Get list of non-null keys
    const keys = Object.keys(course).filter(
        (key) => course[key as keyof UpdateCourse] // If this is not null
    );
    const res = await client<Course[]>`UPDATE courses SET  ${client(course, keys)} WHERE id = ${id} RETURNING *`;
};

Error:

No overload matches this call.
  Argument of type '[string[]]' is not assignable to parameter of type 'readonly ("name" | "description" | "price" | "image")[] | [readonly ("name" | "description" | "price" | "image")[]]'.
    Type '[string[]]' is not assignable to type '[readonly ("name" | "description" | "price" | "image")[]]'.
      Type 'string[]' is not assignable to type 'readonly ("name" | "description" | "price" | "image")[]'.
        Type 'string' is not assignable to type '"name" | "description" | "price" | "image"'.
  Overload 2 of 2, '(template: TemplateStringsArray, ...parameters: readonly ParameterOrFragment<never>[]): PendingQuery<any>', gave the following error.
    Argument of type 'UpdateCourse' is not assignable to parameter of type 'TemplateStringsArray'.
      Type 'UpdateCourse' is missing the following properties from type 'TemplateStringsArray': raw, length, concat, join, and 27 more.

The function does work, but ts it's returning an error either way.

I'm using version 3.4.4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the client imported from ./driver and the updateCourse call shown in the issue, then inspect the postgres 3.4.4 type declarations involved in client(course, keys). Done means the provided TypeScript snippet type-checks without the overload error while retaining its current query behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, postgres, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.