middleware icon indicating copy to clipboard operation
middleware copied to clipboard

scopes from arktype aren't supported in arktype validator

Open lunarW1TCH opened this issue 6 months ago • 5 comments

Which middleware has the bug?

@hono/arktype-validator

What version of the middleware?

2.0.1

What version of Hono are you using?

4.7.11

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

NodeJS 22

What steps can reproduce the bug?

using unextended type works properly

arktypeValidator('json', type({}));

extending arktype using built-in scopes does not:

const scope = type.scope({
  customType: type({})
})

arktypeValidator('json', scope.type({}));

it results in the following error:

Argument of type 'Type<object, { customType: object; }>' is not assignable to parameter of type 'Type<unknown, {}>'. The types of 'as(...).$.exportedNames' are incompatible between these types. Type 'array<"customType">' is not assignable to type 'array'. Type '"customType"' is not assignable to type 'never'.ts(2345)

What is the expected behavior?

it shouldn't affect the behaviour, scopes are only for grouping models for ease of use

What do you see instead?

for middleware to accept types from scopes

Additional information

No response

lunarW1TCH avatar Jun 16 '25 14:06 lunarW1TCH

also looking at the code in middleware/packages/arktype-validator/src/index.ts line 36:

  // @ts-expect-error not typed well

this probably is the culprit

lunarW1TCH avatar Jun 16 '25 14:06 lunarW1TCH

@lunarW1TCH Thank you for the issue.

Hi @MonsterDeveloper. Can you handle this issue?

yusukebe avatar Jun 16 '25 20:06 yusukebe

@yusukebe I looked into it and seems like it would be possible to fix the @hono/arktype-validator

However, the official ArkType docs recommend using Standard Schema for library authors.

Made me wonder, what's the point of supporting the @hono/arktype-validator, @hono/valibot-validator, @hono/zod-validator, etc, when in theory @hono/standard-validator can replace all of them?

The sValidator works perfectly fine with Arktype Scopes (so the issue is not relevant there).

Standard Schema supports a bunch of validators:

Image

Maybe it's time to deprecate individual validators and instead focus on the standard schema?

What do you think?

MonsterDeveloper avatar Jun 17 '25 10:06 MonsterDeveloper

I just switched to sValidator and everything works perfectly :3

lunarW1TCH avatar Jun 17 '25 12:06 lunarW1TCH

@MonsterDeveloper Thank you for the comment.

Maybe it's time to deprecate individual validators and instead focus on the standard schema? What do you think?

I also think it's time. I created the proposal based on your comment: #1241

yusukebe avatar Jun 19 '25 07:06 yusukebe