Type Error with zodValidator and arktypeValidator

Basically I have this
import { arktypeValidator } from "@hono/arktype-validator";
import { type } from "arktype";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import type { ApiResponse } from "shared/dist";

export const app = new Hono()
.use(cors())
.use(logger())
.post(
"/author",
arktypeValidator(
"json",
type({
name: "string",
age: "number",
}),
),
(c) => {
const data = c.req.valid("json");
return c.json({
success: true,
message: `${data.name} is ${data.age}`,
} as ApiResponse);
},
);

export default app;
import { arktypeValidator } from "@hono/arktype-validator";
import { type } from "arktype";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import type { ApiResponse } from "shared/dist";

export const app = new Hono()
.use(cors())
.use(logger())
.post(
"/author",
arktypeValidator(
"json",
type({
name: "string",
age: "number",
}),
),
(c) => {
const data = c.req.valid("json");
return c.json({
success: true,
message: `${data.name} is ${data.age}`,
} as ApiResponse);
},
);

export default app;
and I have this error
No overload matches this call. 13:3:3 typescript 2769
The last overload gave the following error.
Argument of type 'MiddlewareHandler<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>' is not assignable to parameter of type 'H<{}, "/author", BlankInput, HandlerResponse<any>>'.
Type 'MiddlewareHandler<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>' is not assignable to type 'MiddlewareHandler<{}, "/author", BlankInput>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<{}, "/author", BlankInput>' is not assignable to type 'Context<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>'.
Types of property 'env' are incompatible.
Type 'unknown' is not assignable to type 'object | undefined'.
No overload matches this call. 13:3:3 typescript 2769
The last overload gave the following error.
Argument of type 'MiddlewareHandler<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>' is not assignable to parameter of type 'H<{}, "/author", BlankInput, HandlerResponse<any>>'.
Type 'MiddlewareHandler<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>' is not assignable to type 'MiddlewareHandler<{}, "/author", BlankInput>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<{}, "/author", BlankInput>' is not assignable to type 'Context<Env, string, { in: { json: { name: string; age: number; }; }; out: { json: { name: string; age: number; }; }; }>'.
Types of property 'env' are incompatible.
Type 'unknown' is not assignable to type 'object | undefined'.
I get the same error with zodValidator I've tried it.
11 Replies
AbdallahGamal
AbdallahGamalOP2mo ago
here's my package.json
{
"name": "server",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "bun --watch run src/index.ts && tsc --watch"
},
"dependencies": {
"hono": "latest",
"shared": "workspace:*",
"@hono/arktype-validator": "latest",
"arktype": "latest"
},
"devDependencies": {
"@types/bun": "latest"
}
}
{
"name": "server",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "bun --watch run src/index.ts && tsc --watch"
},
"dependencies": {
"hono": "latest",
"shared": "workspace:*",
"@hono/arktype-validator": "latest",
"arktype": "latest"
},
"devDependencies": {
"@types/bun": "latest"
}
}
I'm using bun and a monorepo setup I've used BHVR stack to initialize the repo. if anyone have an idea on why I have this error or a solution that would be great. the api works fine I've tested it with curl
curl -H "Content-Type: application/json" -X POST "http://localhost:3000/author" -d '{"name": "test", "age": 12}'
curl -H "Content-Type: application/json" -X POST "http://localhost:3000/author" -d '{"name": "test", "age": 12}'
AbdallahGamal
AbdallahGamalOP2mo ago
here's a screenshot from my editor
No description
ambergristle
ambergristle2mo ago
can you share your tsconfig?
AbdallahGamal
AbdallahGamalOP2mo ago
// root/tsconfig.json
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Path resolution
"baseUrl": "./",
"paths": {
"@server/*": ["./server/src/*"],
"@client/*": ["./client/src/*"],
"@shared/*": ["./shared/src/*"]
},

// Module resolution
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,

// Strictness and best practices
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"experimentalDecorators": true,

// Output control
"skipLibCheck": true,

// Optional strict flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
// root/tsconfig.json
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Path resolution
"baseUrl": "./",
"paths": {
"@server/*": ["./server/src/*"],
"@client/*": ["./client/src/*"],
"@shared/*": ["./shared/src/*"]
},

// Module resolution
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,

// Strictness and best practices
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"experimentalDecorators": true,

// Output control
"skipLibCheck": true,

// Optional strict flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
// root/server/tsconfig.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
// Environment settings
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",

// Types
"types": ["bun-types"],

// Output settings
"declaration": true,
"outDir": "dist",
"noEmit": false,
"emitDecoratorMetadata": true,

// Module resolution
"moduleResolution": "bundler",
"allowImportingTsExtensions": false
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
// root/server/tsconfig.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
// Environment settings
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",

// Types
"types": ["bun-types"],

// Output settings
"declaration": true,
"outDir": "dist",
"noEmit": false,
"emitDecoratorMetadata": true,

// Module resolution
"moduleResolution": "bundler",
"allowImportingTsExtensions": false
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
ambergristle
ambergristle2mo ago
hm. i can't repro try getting rid of the APIResponse import, for science fwiw, i'd recommend using generic instead of casting:
return c.json<ApiResponse>({
success: true,
message: `${data.name} is ${data.age}`,
});
return c.json<ApiResponse>({
success: true,
message: `${data.name} is ${data.age}`,
});
these are my deps; might be worth using defined versions:
"dependencies": {
"@hono/arktype-validator": "^2.0.1",
"arktype": "^2.1.20",
"hono": "^4.8.5"
}
"dependencies": {
"@hono/arktype-validator": "^2.0.1",
"arktype": "^2.1.20",
"hono": "^4.8.5"
}
i'm on bun 1.2.13, though that shouldn't make a difference out of curiosity, why are you using typescript instead of bun to build? and does the error come up when building, or is it shown in your IDE?
AbdallahGamal
AbdallahGamalOP2mo ago
did you try to create the app with bun create bhvr@latest? this is supposed to be a template ready to use I didn't configure it or add anything just was trying I'm on bun 1.2.18 The type error is in both the IDE and the tsc when building. I'm not sure if there's something wrong the the monorepo setup but I don't think so since is so minimal and contains almost nothing I tried your deps, removed the node_modules and reinstalled everything and still the same error :/
ambergristle
ambergristle2mo ago
i hadnt. i can repro with a new bhvr project no idea, tbh. best guess is that it has something to do with how turbo manages deps or types yep, can confirm if you move the @hono/arktype-validator package from the root-level node modules to the server-specific node modules, there's no error
AbdallahGamal
AbdallahGamalOP2mo ago
They've updated the project to use turbo, I'm on an older version that doesn't use trubo I guess the problem is related to monorepo and not specific to the BHVR stack Do you have any ideas on how can I solve this instead of just moving packages from folder to folder? I think I found a fix I deleted the the bun.lock files and node_modules and reinstalled everything and it worked if you can confirm it I'll make an issue on the bhvr github repo
ambergristle
ambergristle2mo ago
it seems to work 🤷‍♂️
AbdallahGamal
AbdallahGamalOP2mo ago
thank you for your help ❤️
ambergristle
ambergristle2mo ago
np!

Did you find this page helpful?