Skip to content

fix(typings): align callback Pool and PoolConnection types with runtime - #4478

Merged
wellwelwel merged 7 commits into
sidorares:masterfrom
bilashcse:fix/3964-callback-pool-typings
Aug 10, 2026
Merged

fix(typings): align callback Pool and PoolConnection types with runtime#4478
wellwelwel merged 7 commits into
sidorares:masterfrom
bilashcse:fix/3964-callback-pool-typings

Conversation

@bilashcse

Copy link
Copy Markdown
Contributor

Closes #3964

Problem

The callback API typings drifted from the runtime implementation in two places:

  1. PoolConnection.promise() was declared as returning a promise-based Pool, but lib/pool_connection.js returns a PromisePoolConnection. Consumers lost release() and were offered getConnection() instead.
  2. The callback Pool had no escape, escapeId or format, even though lib/base/pool.js implements all three. The promise-based Pool already inherits them from Connection, so the two APIs disagreed and users had to fall back to pool['escape'](...) with the checker silenced.

Changes

  • typings/mysql/lib/PoolConnection.d.tspromise() now returns PoolConnection from mysql2/promise.
  • typings/mysql/lib/Pool.d.ts — adds escape, both escapeId overloads and format, reusing the signatures already declared in Connection.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-error on getConnection() so the return type cannot regress back to Pool.
  • website/docs/examples/connections/create-pool.mdx — documents both behaviours.

Typings, tests and docs only; there is no runtime change.

bilashcse and others added 6 commits August 10, 2026 11:31
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread website/docs/examples/connections/create-pool.mdx
Comment thread test/tsc-build/mysql/createPool/callbacks/promise.test.ts
Comment thread test/tsc-build/mysql/createPool/callbacks/promise.test.ts
Comment thread test/tsc-build/mysql/createPool/callbacks/escape.test.ts
@codecov

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

Copy link
Copy Markdown
Collaborator

Thanks again, @bilashcse

@wellwelwel
wellwelwel merged commit 8b1f829 into sidorares:master Aug 10, 2026
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some types are incorrect on mysql2 (callback based) but not mysql2/promise

3 participants