Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to fix the typescript error from app.use('*', sessionMiddleware(... #18

Open
bkerin opened this issue Aug 4, 2024 · 2 comments
Open

Comments

@bkerin
Copy link

bkerin commented Aug 4, 2024

The home page said it might happen and shows how to ts-ignore, but I'd sort of like to know what it means and maybe how to fix it. For me without the ts-ignore deno says:

error: TS2769 [ERROR]: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'MiddlewareHandler' is not assignable to parameter of type 'MiddlewareHandler<{ Variables: { session: Session; session_key_rotation: boolean; }; }, "*", {}>'.
      Types of parameters 'c' and 'c' are incompatible.
        Type 'Context<{ Variables: { session: Session; session_key_rotation: boolean; }; }, "*", {}>' is not assignable to type 'Context<any, string, {}>'.
          Property '#private' in type 'Context' refers to a different member that cannot be accessed from within type 'Context'.
app.use('*', sessionMiddleware({
             ^
    at file:///home/bkerin/projects/test/web_server/deno_tsx_test.tsx:159:14

I'm pretty new to typescript and have to admit I find this pretty hard to decipher especially the mismatch between type 'Context' ... with type 'Context' bit. Any clues?

@jcs224
Copy link
Owner

jcs224 commented Sep 14, 2024

Don't worry, TypeScript is very confusing to me too 😅 I'm figuring it out as I go.

When you created your app, did you include the extra TypeScript generics?

const app = new Hono<{
  Variables: {
    session: Session,
    session_key_rotation: boolean
  }
}>()

@DywiTom
Copy link

DywiTom commented Oct 30, 2024

The error appears if you use

import { Hono } from 'jsr:@hono/hono'

instead of

import { Hono } from 'npm:hono'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants