hono icon indicating copy to clipboard operation
hono copied to clipboard

c.Var types unknown

Open janat08 opened this issue 9 months ago • 3 comments

What version of Hono are you using?

4.2.7

What runtime/platform is your app running on?

CF Workers

What steps can reproduce the bug?

` const redirectHtmx: MiddlewareHandler<{ Variables: { redirectHtmx: (url: string) => Response } }> = async (c, next) => { c.set('redirectHtmx', (url: string) => new Response(null, {headers: {'HX-Location': url}})) await next() } app.use('*', redirectHtmx)

c.var.redirectHtmx('/page') is of type unkown `

What is the expected behavior?

https://hono.dev/api/context#var

What do you see instead?

is of type unkown on additional methods

Additional information

No response

janat08 avatar Apr 25 '24 05:04 janat08

I think you have to write the env generics to Hono instance. Screenshot 2024-04-25 at 15 48 15

sor4chi avatar Apr 25 '24 06:04 sor4chi

Makes sense, but then the docs are wrong.

janat08 avatar Apr 25 '24 09:04 janat08

That's true. I'll fix it later!

sor4chi avatar Apr 25 '24 09:04 sor4chi

Hi, @janat08 The website has been updated! Thanks!

sor4chi avatar Apr 30 '24 03:04 sor4chi

@janat08 @sor4chi Thanks!

Closing the issue.

yusukebe avatar May 01 '24 04:05 yusukebe