node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

typeCast Next type appears to be incorrect

Open bbugh opened this issue 1 year ago • 3 comments

Problem

The current return type of Next is void. This led to a bug in the code because as currently typed, the return value of next appears to be unnecessary.

https://github.com/sidorares/node-mysql2/blob/9ba3706d4726fd951b83dfcec2280705875cbae2/typings/mysql/lib/parsers/typeCast.d.ts#L52-L54

I discovered in my code that unless next() was returned, this function would result in many undefined values. However, in every case that I can find it, next is called as return next(). If it is not returned, the result is empty data.

// bad, results in all `undefined` values:
typeCast: (field, next) => { next() }

// good, returns expected results
typeCast: (field, next) => { return next() }

Additionally, typescript-eslint correctly raises an error on this with the @typescript-eslint/no-confusing-void-expression rule:

Example 1 Pasted_Image_10_15_24__1_49 PM

Example 2 image

Proposed solution

Since the return value is required, but the type is not known, the unknown type seems like the most correct option here. I tested and this resolves the issue.

mysql2/typings/mysql/lib/parsers/typeCast.d.ts
-export type Next = () => void;
+export type Next = () => unknown;

I can submit a PR if requested (and it will be accepted).

bbugh avatar Oct 15 '24 18:10 bbugh