Skip to content

fix: types for query values#3985

Merged
wellwelwel merged 6 commits into
sidorares:masterfrom
uPaymeiFixit:master
Feb 20, 2026
Merged

fix: types for query values#3985
wellwelwel merged 6 commits into
sidorares:masterfrom
uPaymeiFixit:master

Conversation

@uPaymeiFixit

Copy link
Copy Markdown
Contributor

Fixes #3982

@codecov

This comment was marked as off-topic.

@uPaymeiFixit

Copy link
Copy Markdown
Contributor Author

@wellwelwel I see you added the needs documentation tag. Is this what you had in mind?
image

@wellwelwel

Copy link
Copy Markdown
Collaborator

I see you added the needs documentation tag. Is this what you had in mind?

Yes, thanks @uPaymeiFixit! I don't know how these types perform in general with variations such as placeholders, nested arrays, and complex parameter combinations, especially in the case of query, which allows for more flexible values. That's why I put the needs investigation label on it.

For TypeScript, there are compilation tests (which do not execute code, but only check types usage), for example:

conn.query<mysqlp.ProcedureCallPacket>(sql).then(([_r, _f]) => {
const result:
| [mysqlp.RowDataPacket[], mysqlp.ResultSetHeader]
| mysqlp.ResultSetHeader = _r;
const fields: mysqlp.FieldPacket[] = _f;
console.log(result, fields);
});

You can run them with test:tsc-build 🙋🏻‍♂️

@uPaymeiFixit

Copy link
Copy Markdown
Contributor Author

Awesome! I ran the test:tsc-build script and it looks like it succeeded (exited with 0).
As far as investigation goes, I initially did a lot of playing around with the type to make sure it was accurate. I think it should reflect what types are actually possible. Here's a tsplayground that shows what's possible and what's not.

@wellwelwel

wellwelwel commented Feb 17, 2026

Copy link
Copy Markdown
Collaborator

@uPaymeiFixit, my main concern was how these types would behave with named-placeholders. By migrating the entire ESM test suite to TypeScript in #4086, the types you created are now tested. You can check it with npm run typecheck 🙋🏻‍♂️

@uPaymeiFixit

Copy link
Copy Markdown
Contributor Author

Good catch, I completely forgot about named placeholders. In case it's helpful, I also updated my tsplayground test.

@wellwelwel

wellwelwel commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks again, @uPaymeiFixit!

Just to be sure, I tried a random case with nested arrays:

query('INSERT ...', ['john', 30, [[[{a: true}], 6]]]); // ✅

Comment thread website/docs/documentation/typescript-examples.mdx
@wellwelwel wellwelwel merged commit a9c8d09 into sidorares:master Feb 20, 2026
101 checks passed
mdierolf pushed a commit to CloudQuote/node-mysql2 that referenced this pull request May 23, 2026
* fix: types for query values

* docs: add TypeScript documentation for QueryValues

* fix: support named placeholders in QueryValues type

* Update website/docs/documentation/typescript-examples.mdx

---------

Co-authored-by: Weslley Araújo <46850407+wellwelwel@users.noreply.github.com>
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.

Type of value is incorrect (Type is any, should be more specific)

2 participants