I have the following Typescript function that query a table in Postgresql;I pass a generic type and I expect to have an array of objects of the same type passed as input, but it doesn’t:
export async function pgQuery<T>(
query: string,
postgreSqlClient: Client = postgreSqlClientGlobal
) {
const log = extendLogger(_log, pgQuery);
try {
const res = await postgreSqlClient.query<T>(query);
return res;
} catch (error) {
log.error({ error }, `PostgreSql query ERROR`);
throw new Error(`PostgreSql query ERROR - ${error}`);
}
}
The input type T is:
{country: string,
age_min: number,
age_max: number}
And in the table of the Postgresql DB I have records like this:
{
loc_name: "Albania",
age_min: 15,
age_max: 64
}
but I have, as output of the executed query, object like this:
{country: string,
age_min: string,
age_max: string}
Example:
{
loc_name: "Albania",
age_min: "15",
age_max: "64"
}
How to retrieve the correct types?