middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Types of typiaValidator in typia-validator are not compatible with hono 4.x

Open jirutka opened this issue 1 year ago • 1 comments

Which middleware has the bug?

@hono/typia-validator

What version of the middleware?

0.1.0

What version of Hono are you using?

4.6.17

What runtime/platform is your app running on? (with version if possible)

Node.js

What steps can reproduce the bug?

I noticed two problems:

  1. ~~typia.http.createValidateQuery doesn’t work, it throws TypeError: xxx.get is not a function (in the most basic case, so reproduction is trivial).~~ (My fault, I imported typiaValidator from @hono/typia-validator instead of @hono/typia-validator/http.)

  2. There’s a type error in packages/typia-validator/src/index.ts:32-51:

Type 'MiddlewareHandler<E, P, { in: { [K in Target]: K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }; }; out: { [K_1 in Target]: any; }; }>' is not assignable to type 'MiddlewareHandler<E, P, V>'.
  Types of parameters 'c' and 'c' are incompatible.
    Type 'Context<E, P, V>' is not assignable to type 'Context<E, P, { in: { [K in Target]: K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }; }; out: { [K_1 in Target]: any; }; }>'.
      Type 'V' is not assignable to type '{ in: { [K in Target]: K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }; }; out: { [K_1 in Target]: any; }; }'.
        Type '{ in: { [K in Target]: O; }; out: { [K in Target]: O; }; }' is not assignable to type '{ in: { [K in Target]: K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }; }; out: { [K_1 in Target]: any; }; }'.
          Types of property 'in' are incompatible.
            Type '{ [K in Target]: O; }' is not assignable to type '{ [K in Target]: K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }; }'.
              Type 'O' is not assignable to type 'K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }'.
                Type 'OutputType<T>' is not assignable to type 'K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }'.
                  Type 'unknown' is not assignable to type 'K extends "json" ? unknown : { [x: string]: ValidationTargets[K][string]; }'.ts(2322)

And I cannot figure out how to fix it, this type is incredibly complex.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

jirutka avatar Jan 22 '25 13:01 jirutka

@jirutka Thank you for raising the issue.

Hi @dworznik, can you handle this?

yusukebe avatar Jan 23 '25 01:01 yusukebe