fix(types): type pg Client as the constructor (typeof Pg.Client)#219
Open
imharjot wants to merge 1 commit into
Open
fix(types): type pg Client as the constructor (typeof Pg.Client)#219imharjot wants to merge 1 commit into
imharjot wants to merge 1 commit into
Conversation
The plugin assigns `pg.Client` (the class) to `app.pg.Client` at runtime, but the `PostgresDb` type declared it as `Pg.Client` (an instance). This made `new app.pg.Client(...)` fail to type-check with TS2351 "This expression is not constructable" even though it works at runtime. Type the member as `typeof Pg.Client` so it reflects the constructor, and update the type test to assert against `typeof Client`. Signed-off-by: Harjot Singh <harjotsrance@gmail.com>
Eomm
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Change the
Clientmember of the publicPostgresDbtype fromPg.Clienttotypeof Pg.Client.Why
At runtime the plugin assigns the pg Client class (the constructor) to
app.pg.Client:But the type declaration described it as an instance:
Since
@types/pgdeclaresexport class Client,Pg.Clientis the instance type andtypeof Pg.Clientis the constructor type. As a result, instantiating a one-off client via the decorator —new app.pg.Client({ connectionString })— failed to type-check:even though it works at runtime.
Change
and the corresponding type test now asserts the constructor type:
Testing
npm run test:typescript(tstyche): all 4 type-test files pass, 13/13 assertions pass.npm run lint: clean.new app.pg.Client({ connectionString })now type-checks (no TS2351), and reproduced the failure before the change.This is a type-only change with no runtime impact, so unit-test coverage (
c8 --100) is unaffected.