ANSWER: You can't
From here I know that to check if a value is a list you can use Array.isArray() but I have an odd situation where I have a query function
export async function query<T = unknown>(sql: string, options?: unknown): Promise<T> {
const pool = await initializePool()
const result = await pool.query(sql, options);
return /* T is of type list */ ? result : [result];
}
I can't use Array.isArray() on the type and I was wondering if there was some sort of typeof function I can use on the T.
The problem is, pool.query always returns an array and I'd like to destructure it immediately if possible
const initializePool = async () => {
if (pool) {
return pool;
}
const CREDS = { connectionLimit: 500000, ...MYSQL_CREDS, multipleStatements: true }
pool = await mysql.createPool(CREDS)
return pool
}