I have code similar to this - very simple just to show the case.
this.getCode = (code: string): Promise<codeObject | false> => {
return new Promise((resolve, reject) => {
pool.query('SELECT * FROM ?? WHERE code = ?', [TABLE, code], function (err, result) {
if (err) {
return reject(err);
}
if (result.length === 0) {
return resolve(false);
}
});
});
};
Problem is in line if (result.length === 0) {, the error is error TS2339: Property 'length' does not exist on type 'RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[]'.
I can not find any way to redefine OkPacket to at least have length?: number
that would be enought for ignore that error (most selects do not get OkPackets anyway and i dont wanna have to check type on each select if what i got is not OkPacket when i know it isnt)...