Skip to content
Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

Pinter Computing

Knowledge Base for IT Professionals, Teachers, and Astronauts

  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
  • Home
  • Programming
  • DevOps
  • Project Management
  • Software and Hardware
  • Miscellaneous
  • Egyebek
  • About
  • Experience
  • Education
  • Contact
Close

Search

Home/Knowledge Base/Argument of type ‘(number | null)[]’ is not assignable to parameter of type ‘(err: Error, result: QueryResult) => void’
Knowledge Base

Argument of type ‘(number | null)[]’ is not assignable to parameter of type ‘(err: Error, result: QueryResult) => void’

By Laszlo Pinter
April 1, 2024 3 Min Read
0

The latest “npm install @types/pg –save-dev” command changed the “@types/pg” Node.js module version in the package.json file from to “^8.11.4”.

Since that, the build of my TypeScript applications fail with the error message below, if the PostgreSQL .query function contains mixed “value” types, like this:

const query = "INSERT INTO ..."
const values = [string, number, stringArray, nullableValue]
const result = await conn.query(
      query,
      values
    );   

The error message is:

.. : error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type ‘(number | null)[]’ is not assignable to parameter of type ‘(err: Error, result: QueryResult) => void’.
Type ‘(number | null)[]’ provides no match for the signature ‘(err: Error, result: QueryResult): void’.

or

…: error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type ‘(string | number)[]’ is not assignable to parameter of type ‘(err: Error, result: QueryResult) => void’.

or

… : error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type ‘(string | number | null)[]’ is not assignable to parameter of type ‘(err: Error, result: QueryResult) => void’.
Type ‘(string | number | null)[]’ provides no match for the signature ‘(err: Error, result: QueryResult): void’.

Solution

I can see two solutions:

Make sure all elements of the array have the same data type

If possible, make sure the type of all value elements is the same, the simplest is to

  • convert numeric values to strings,
  • specify default values for “null” values,
  • convert string arrays to strings, or get the first element if only that has value.
const values = [number.toString(), canBeNullString || '' (canBeNullNumber || 0).toString(), stringArray[0]]

A better solution is to centralize the database access

If the database access is centralized in a function, and the values are passed in as “any” type, the TypeScript compiler will not reject it, because it does not iterate through all references of the function.

This is an example of the centralized PostgreSQL database call.
Install the required Node.js packages with

npm install typescript --save-dev
npm install @types/node --save-dev
npm install dotenv
npm install pg
npm install @types/pg --save-dev

The centralized PostgreSQL access file

// db.js

import * as dotenv from "dotenv";
dotenv.config()
import pg from 'pg'

// Create the reusable pool to the PostgreSQl database
// Read config values from environment variables
let conn = new pg.Pool({
  user: process.env.USER_NAME,
  password: process.env.PASSWORD,
  host: process.env.HOST,
  port: parseInt(process.env.PORT || "5432"),
  database: process.env.DATABASE,
});

// Call the "query" method of the pool to execute the text of the query with optional parameters
export const query = async (text: string, params: any) => {
  let res;

  try{

    if (params) {
      // There are parameters, send them with the query text
      res = await conn.query(text, params)
    } else {
      // There are no parameters
      res = await conn.query(text)
    }

  } catch (e) {
    // There is an error executing the query, log the error, the text of the query and the parameters
    console.log('error', e)
    console.log('query', text)
    console.log('params', params)
  }

  return res
}
  
export default query ;

Call the centralized function with

// selectData.ts

import * as conn from './db';

export async function selectData (id: string) {

  let result;
  let query;
  let values;

  try {
    
    // Build the query
    const baseQuery = "SELECT * FROM table";  

      query = baseQuery + ' ' + "WHERE id = $1";
      values = [id]

    // Query the database
    result = await conn.query(
        query
        , values
    );

    return result?.rows[0];

  } catch ( error ) {
    console.log("In selectData", error);
    console.log("result: ", result);
    console.log("query: ", query);
    console.log("values: ", values)
    return null;
    }
};
Author

Laszlo Pinter

Follow Me
Other Articles
Previous

Cities: Skylines II Developer Mode

Next

How to stop the rain and snow in Cities: Skylines II

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Last Changes

  • DevOps Engineering part 1. (Mac) - Make your Macintosh easier to use June 25, 2026
  • Japan travel tips June 22, 2026
  • How to stop the rain and snow in Cities: Skylines II June 20, 2026
  • Cities: Skylines II Developer Mode June 20, 2026
  • 'CSII_MANAGEDPATH' has incorrect path(s) when building Cities: Skylines II mod June 20, 2026

Tags

.NET .NETcore 3Dprinting ASP.NET Core AutodeskInventor AWS C# Chef cloud DevOps Docker EntityFramework Games Git Go iOS iPad iPhone iPod Java Kubernetes Linux MacOSX MSSQL MVC Node.js Packer PowerShell Python RDS RightScale Ruby security Splunk TeamCity Terraform TestKitchen Tomcat Ubuntu Vagrant VirtualBox VisualStudio Windows WordPress Xcode

Recent Comments

  • Zengei László on MyHeritage családfa exportálása és küldése emailben
  • Raúl Castillo on DynDns update error
  • MICHAEL on Windows Media Player 12 cannot find the album information
  • Nargis on Configure Epson ET-3850 scanning on Windows 11
  • Venczelné Zemen Erika on Delta S2302 termosztát programozása

–

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright 2026 — Pinter Computing. All rights reserved.