Open bakasmarius opened 3 days ago
Context generics (specifically, Input) are inferred differently in Deno and Node for the same code.
Context
Input
Deno
Node
Deno: v1.46.3; v2.0.3; v2.0.4 Node: v20.18.0 Hono: v4.6.8 @hono/zod-validator: v0.4.1 zod: v3.23.8
Node code:
import { Hono } from 'hono' import { z } from 'zod' import { zValidator } from '@hono/zod-validator' const app = new Hono().put( '/posts', zValidator('json', z.object({ id: z.number() })), (c) => { const json = c.req.valid('json') return c.json({ status: 'ok' }) } )
TypeScript infers c to:
c
(parameter) c: Context<{}, "/posts", { in: { json: { id: number; }; }; out: { json: { id: number; }; }; }>
Deno code:
import { z } from 'npm:zod@3.23.8' import { zValidator } from 'npm:@hono/zod-validator@0.4.1' import { Hono } from 'npm:hono@4.6.8' const app = new Hono().put( '/posts', zValidator('json', z.object({ id: z.number() })), (c) => { const json = c.req.valid('json') return c.json({ status: 'ok' }) }, )
(parameter) c: Context<{}, "/posts", BlankInput>
Which results in c.req.valid('json') error: Argument of type 'string' is not assignable to parameter of type 'never'.deno-ts(2345)
c.req.valid('json')
Argument of type 'string' is not assignable to parameter of type 'never'.deno-ts(2345)
Hi @bakasmarius
It is not reproduced. Works well in my environment:
Please clear the cache and try it again:
deno cache --reload main.ts
Context
generics (specifically,Input
) are inferred differently inDeno
andNode
for the same code.Deno: v1.46.3; v2.0.3; v2.0.4 Node: v20.18.0 Hono: v4.6.8 @hono/zod-validator: v0.4.1 zod: v3.23.8
Node code:
TypeScript infers
c
to:Deno code:
TypeScript infers
c
to:Which results in
c.req.valid('json')
error:Argument of type 'string' is not assignable to parameter of type 'never'.deno-ts(2345)