You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect type definitions causing confusion when trying to catch PostgresError #862
I noticed that when I want to catch an error and identify it using instanceof I got an error TypeError: Right-hand side of 'instanceof' is not an object. Which was caused by following code:
import{PostgresError}from'postgres';try{// await query}catch(e){if(einstanceofPostgresError){// do something}}
To fix that I had to use default import:
importPostgresfrom'postgres';try{// await query}catch(e){if(einstanceofPostgres.PostgresError){// do something}}
This is confusing because typescript was not able to catch the failing example as something wrong and I was able to find this error only in runtime.
Reacted by josh-i386g, William Darian, Nathan Kleyn, Gabor Csizmadia, Zach Stence and Martin Ždila
There is no PostgresError named export so the first sample doesn't make sense and I don't know typescript so feel free to do a PR that fixes the ts issue.
1 | (function (entry, fetcher)
^
SyntaxError: Export named 'PostgresError' not found in module '/Users/dimiguel/dev/ladder-v3/node_modules/postgres/src/index.js'.
Activity
porsager commentedon May 15, 2024
There is no PostgresError named export so the first sample doesn't make sense and I don't know typescript so feel free to do a PR that fixes the ts issue.
divmgl commentedon Feb 19, 2025
This also causes an error in Bun:
v4