Skip to content

Passing raw object to JSON field results in typescript error #587

Closed
@hanszoons

Description

@hanszoons

I have a table with a column of type 'JSON' (plain, not JSONB). I have a js object that I want to store in the database.

I am using the following (simplified) function:

/**
 * @param {object} object_json
 * @returns {Promise<void>}
 */
export async function insert_json(object_json) {
  await sql`
    INSERT INTO 
      schema.table (field_json)
    VALUES (${object_json}::json)
  `;
}

This works, but vscode returns a typescript error that I can't make much of:

No overload matches this call.
  Overload 1 of 2, '(first: TemplateStringsArray, ...rest: never): PendingQuery<Row[]>', gave the following error.
    Argument of type 'object' is not assignable to parameter of type 'never'.
  Overload 2 of 2, '(template: TemplateStringsArray, ...parameters: readonly ParameterOrFragment<bigint>[]): PendingQuery<Row[]>', gave the following error.
    Argument of type 'object' is not assignable to parameter of type 'ParameterOrFragment<bigint>'.ts(2769)

I've tried all kinds of things to get rid of it, but I don't see the error. I found a similar comment here: #556 and here #415, but these were closed with no mention of solution.

Any idea what I am doing wrong?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions