Closed ipython3 closed 2 months ago
The problem is ;
const result = await pool.query('SELECT COUNT(*) FROM users;');
//---------------------------------------------------------^
the char ;
is used for multi statement sintax, eg.:
const result = await pool.query('SELECT COUNT(*) FROM users; SELECT COUNT(*) FROM orders;');
Operating System: Ubuntu jammy 22.04 x86_64 node: 20.15.0 vscode: 1.91.0 pg: 8.12.0
Hi,
Thank you for creating this amazing library! I've just started using
pg
and ran into a strange problem.In
pg
's documentation, I can see that the type of result.rows should beany[]
.I'm writing a Node.js server that need to get the total user count in the
user
table in my database. So I wrote JavaScript code like this:The code can run smoothly without any error, but my editor (VS Code) detects the type of result.rows as
any[][]
. Thus I get an linting error which saysProperty 'count' does not exist on type 'any[]'.
I'm wondering if I'm using
pg
incorrectly? Or if I have configured VS Code incorrectly? If the type of result.rows isany[]
according topg
's documentation, why VS Code detects the type of it asany[][]
? I'm not familiar with TypeScript and I'm wondering if there is a proper way to handle this linting error? Maybe writing some JSDoc comments?My
jsconfig.json
file: