Skip to content

typeCast Next type appears to be incorrect #3122

Description

@bbugh

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
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).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions