Marksmith
Marksmith14mo ago

applyWSSHandler yells at context error in express

I used the example code from docs. My applyWSSHandler code is:
const handler = applyWSSHandler({wss, router: appRouter, createContext});
const handler = applyWSSHandler({wss, router: appRouter, createContext});
I see the next error on createContext:
TS2322: Type '({ req, res, }: CreateExpressContextOptions) => Promise<{ req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>; res: Response<...>; }>' is not assignable to type 'NodeHTTPCreateContextFn<CreateRouterInner<RootConfig<{ ctx: { req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>; res: Response<any, Record<string, any>>; }; meta: object; errorShape: { ...; }; transformer
TS2322: Type '({ req, res, }: CreateExpressContextOptions) => Promise<{ req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>; res: Response<...>; }>' is not assignable to type 'NodeHTTPCreateContextFn<CreateRouterInner<RootConfig<{ ctx: { req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>; res: Response<any, Record<string, any>>; }; meta: object; errorShape: { ...; }; transformer
The createContext function was copied from examples as well. I just made it to return req and res instead of the empty object:
export async function createContext({req, res}: trpcExpress.CreateExpressContextOptions) {return {req, res}}
export async function createContext({req, res}: trpcExpress.CreateExpressContextOptions) {return {req, res}}
How should I change the createContext function to make it work? I have a problem while trying to write tests probably because of this too.
0 Replies
No replies yetBe the first to reply to this messageJoin