node-mysql2
node-mysql2 copied to clipboard
typeCast Next type appears to be incorrect
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
Example 2
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).