fix(typings): align callback Pool and PoolConnection types with runtime - #4478
Merged
wellwelwel merged 7 commits intoAug 10, 2026
Merged
Conversation
The callback-based PoolConnection.promise() was typed as returning a promise-based Pool, but lib/pool_connection.js returns a PromisePoolConnection. Refs sidorares#3964
lib/base/pool.js implements format, escape and escapeId, and the promise-based Pool already inherits them from Connection. The callback-based Pool typings were missing them. Refs sidorares#3964
Compile-time guard so the return type cannot regress back to Pool. Refs sidorares#3964
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns callback pool typings with runtime behavior and documents the corrected APIs.
Changes:
- Corrects
PoolConnection.promise()and adds pool escaping helpers. - Adds compile-time regression coverage.
- Documents both behaviors.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
typings/mysql/lib/PoolConnection.d.ts |
Corrects the promise wrapper return type. |
typings/mysql/lib/Pool.d.ts |
Declares pool escaping and formatting helpers. |
test/tsc-build/mysql/createPool/callbacks/promise.test.ts |
Tests the corrected wrapper type. |
test/tsc-build/mysql/createPool/callbacks/escape.test.ts |
Tests helper typings. |
website/docs/examples/connections/create-pool.mdx |
Documents the corrected APIs. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This comment was marked as off-topic.
This comment was marked as off-topic.
pool.escape, pool.escapeId and pool.format are now typed, so the three "TODO: implement typings" suppressions in test-pool.test.mts are unused and fail tsc with TS2578.
wellwelwel
approved these changes
Aug 10, 2026
Collaborator
|
Thanks again, @bilashcse ✨ |
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.
Closes #3964
Problem
The callback API typings drifted from the runtime implementation in two places:
PoolConnection.promise()was declared as returning a promise-basedPool, butlib/pool_connection.jsreturns aPromisePoolConnection. Consumers lostrelease()and were offeredgetConnection()instead.Poolhad noescape,escapeIdorformat, even thoughlib/base/pool.jsimplements all three. The promise-basedPoolalready inherits them fromConnection, so the two APIs disagreed and users had to fall back topool['escape'](...)with the checker silenced.Changes
typings/mysql/lib/PoolConnection.d.ts—promise()now returnsPoolConnectionfrommysql2/promise.typings/mysql/lib/Pool.d.ts— addsescape, bothescapeIdoverloads andformat, reusing the signatures already declared inConnection.d.ts.test/tsc-build/mysql/createPool/callbacks/escape.test.ts— compile-time coverage for the escaping helpers.test/tsc-build/mysql/createPool/callbacks/promise.test.ts— compile-time coverage for.promise(), with a@ts-expect-errorongetConnection()so the return type cannot regress back toPool.website/docs/examples/connections/create-pool.mdx— documents both behaviours.Typings, tests and docs only; there is no runtime change.