You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: Context's session is not properly typed despite the type definitions.
Actual behavior
declare module "koa-generic-session"{interfaceSession{foo: "bar";}}app.use((ctx)=>{// session is any.let{ session }=ctx;// This is fine.session.cookie="hahahaha !";// foo is anyletfoo=session.foo;});
Expected behavior
declare module "koa-generic-session"{interfaceSession{foo: "bar";}}app.use((ctx)=>{// session is Session.let{ session }=ctx;// The line below is a type error.// session.cookie = "hahahaha !";// foo is "bar"letfoo=session.foo;});
Code to reproduce
main.ts
importkoafrom"koa";importsession,{Session}from"koa-generic-session";letstore: Record<string,Session>={};declare module "koa-generic-session"{interfaceSession{foo: "bar";}}constapp=newkoa();app.use(session({store: {get(key: string){returnstore[key];},set(key: string,sess: Session){store[key]=sess;},destroy(key: string){deletestore[key];},},}),);app.use((ctx)=>{// session is any but should be Session.let{ session }=ctx;// This is fine but shouldn't.session.cookie="hahahaha !";// foo is any but should be "bar".letfoo=session.foo;});app.listen(8080);
Thanks for the answer! This makes sense. Unfortunately, I am afraid I won't be able to work on this myself, at least in the time being. Just to clarify, you are talking about a PR to https://github.com/DefinitelyTyped/DefinitelyTyped, is it?
Describe the bug
Node.js version: 18.12.1
Typescript version: 4.9.4
Koa version: 2.14.1 (types: 2.13.5)
OS version: Mac OS 13.0.1
Description: Context's
session
is not properly typed despite the type definitions.Actual behavior
Expected behavior
Code to reproduce
main.ts
package.json
tsconfig.json
Checklist
Potential fix or workaround
At the moment, I need to manually define the context type for my app:
Is this the intended use?
The text was updated successfully, but these errors were encountered: