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

Incorrect type for createContext params for trpc-server #938

Open
paymog opened this issue Jan 17, 2025 · 0 comments
Open

Incorrect type for createContext params for trpc-server #938

paymog opened this issue Jan 17, 2025 · 0 comments
Labels

Comments

@paymog
Copy link

paymog commented Jan 17, 2025

Which middleware has the bug?

@hono/trpc-server

What version of the middleware?

^0.3.4

What version of Hono are you using?

^4.6.15

What runtime/platform is your app running on? (with version if possible)

node 20

What steps can reproduce the bug?

I'm using trpcServer like so

app.use(
  "/trpc/*",
  trpcServer({
    router: appRouter,
    createContext: (opts, c) => createContext(opts),
    onError({ error }) {
      console.error(error);
    },
  }),
);

I have the trpc createContext function defined like so

export const createContext = async (c: CreateNextContextOptions) => {
///stuff
}

It seems that the opts passed in from the trpc-server package is of type incompatible with the CreateNextContextOptions param as documented here

What is the expected behavior?

I expect the types for opts to match the types for the createContext of trpc.

What do you see instead?

Type types do not match

src/main.ts:36:47 - error TS2345: Argument of type 'FetchCreateContextFnOptions' is not assignable to parameter of type 'CreateNextContextOptions'.
  Property 'res' is missing in type 'FetchCreateContextFnOptions' but required in type 'CreateNextContextOptions'.

36     createContext: (opts, c) => createContext(opts),
                                                 ~~~~

  ../node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/adapters/node-http/types.d.ts:68:5
    68     res: TResponse;
           ~~~
    'res' is declared here.

Additional information

I'm using trpc v10

@paymog paymog added the triage label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant