HonoH
Hono12mo ago
pastilhas

Trouble with Hono and Typescript

I have a fully working server, built with Hono.
I am now, implementing typescript in my codebase.
This is my main file (paraphrased)
app.get('/me', userMiddleware, usersMe);
app.post('/signin', signinHandler);
app.post('/signup', signupHandler);
app.post('/verify', verifyHandler);
app.post('/change-password', userMiddleware, changePasswordHandler);
app.post('/forgot-password', forgotPasswordHandler);
app.post('/reset-password', resetPasswordHandler);
app.post('/invite', userMiddleware, inviteUserHandler);
app.post('/resend-invite', userMiddleware, resendInvitationHandler);
app.route('/passkeys', passkeyRouter);


each handler and middleware are exported from separate files, like:
export const verifyHandler = async (ctx) => {
   ....
  return ctx.json({ ok: true });
};

so, apparently, inside this file, the typescript server doesn't know this is supposed to be a route handler so ctx is "implicitly typed as any".

What is the best way to do this?
And where can i find documentation on this?

Thank you
Was this page helpful?