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.
|
export type Next = () => void; |
|
|
|
export type TypeCast = ((field: Field, next: Next) => any) | boolean; |
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).
Problem
The current return type of
Nextisvoid. This led to a bug in the code because as currently typed, the return value ofnextappears to be unnecessary.node-mysql2/typings/mysql/lib/parsers/typeCast.d.ts
Lines 52 to 54 in 9ba3706
I discovered in my code that unless
next()was returned, this function would result in manyundefinedvalues. However, in every case that I can find it,nextis called asreturn next(). If it is not returned, the result is empty data.Additionally, typescript-eslint correctly raises an error on this with the
@typescript-eslint/no-confusing-void-expressionrule:Example 1

Example 2

Proposed solution
Since the return value is required, but the type is not known, the
unknowntype seems like the most correct option here. I tested and this resolves the issue.I can submit a PR if requested (and it will be accepted).