Description
Code
const assert = require('assert');
const {Pool} = require('pg');
const pg = new Pool();
assert(pg instanceof Pool);
Expected
Should run fine.
Actual
AssertionError [ERR_ASSERTION]: false == true
Versions
$ node -v
v8.11.1
$ npm -v
5.8.0
$ npm ls pg-pool
<project>
└─┬ pg@7.4.1
└── pg-pool@2.0.3
I am building a wrapper that accepts either Pool
or Connection
and want to have listeners for pool's events, but not client's. To work around this issue I am using instanceof
with right-hand side of Pool.super_
. Not sure if this property is intended to be used that way, or won't change later since docs don't mention its existence.
assert(new Pool() instanceof pg.Pool); // throws
assert(new Pool() instanceof pg.Pool.super_); // passes
I'd propose to fix this by adding and exporting a static method that's something like Pool.new(options)
instead of exporting a wrapper function. We can keep super_
on it as a property as well, so change won't be semver-breaking. If this is not feasible given dependency on pg-pool
module, we can inherit from there with only difference being Pool.Client
.