mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
express-session: fix Store#get callback parameter type (#23240)
The type of the second parameter of Store#get should be SessionData, not Session. It's bit confusing because parameter name "session" is used for both Session and SessionData on their documentation.
This commit is contained in:
committed by
Sheetal Nandi
parent
38ebf1ed54
commit
2ab14041f4
@@ -37,3 +37,34 @@ app.use((req, res, next) => {
|
||||
res.end('welcome to the session demo. refresh!');
|
||||
}
|
||||
});
|
||||
|
||||
// Custom Session Store
|
||||
|
||||
class MyStore extends session.Store {
|
||||
private sessions: { [sid: string]: string };
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.sessions = {};
|
||||
}
|
||||
|
||||
get = (sid: string, callback: (err: any, session: Express.SessionData) => void): void => {
|
||||
callback(null, JSON.parse(this.sessions[sid]));
|
||||
}
|
||||
|
||||
set = (sid: string, session: Express.Session, callback: (err: any) => void): void => {
|
||||
this.sessions[sid] = JSON.stringify(session);
|
||||
callback(null);
|
||||
}
|
||||
|
||||
destroy = (sid: string, callback: (err: any) => void): void => {
|
||||
this.sessions[sid] = undefined;
|
||||
this.sessions = JSON.parse(JSON.stringify(this.sessions));
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
app.use(session({
|
||||
secret: 'keyboard cat',
|
||||
store: new MyStore()
|
||||
}));
|
||||
|
||||
Vendored
+4
-4
@@ -1,6 +1,6 @@
|
||||
// Type definitions for express-session 1.15
|
||||
// Project: https://www.npmjs.org/package/express-session
|
||||
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>, Jacob Bogers <https://github.com/jacobbogers>
|
||||
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>, Jacob Bogers <https://github.com/jacobbogers>, Naoto Yokoyama <https://github.com/builtinnya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
@@ -64,7 +64,7 @@ declare namespace session {
|
||||
}
|
||||
|
||||
interface BaseMemoryStore {
|
||||
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
|
||||
get: (sid: string, callback: (err: any, session: Express.SessionData) => void) => void;
|
||||
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
|
||||
destroy: (sid: string, callback: (err: any) => void) => void;
|
||||
length?: (callback: (err: any, length: number) => void) => void;
|
||||
@@ -78,7 +78,7 @@ declare namespace session {
|
||||
load: (sid: string, fn: (err: any, session: Express.Session) => any) => void;
|
||||
createSession: (req: express.Request, sess: Express.SessionData) => void;
|
||||
|
||||
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
|
||||
get: (sid: string, callback: (err: any, session: Express.SessionData) => void) => void;
|
||||
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
|
||||
destroy: (sid: string, callback: (err: any) => void) => void;
|
||||
all: (callback: (err: any, obj: { [sid: string]: Express.SessionData; }) => void) => void;
|
||||
@@ -87,7 +87,7 @@ declare namespace session {
|
||||
}
|
||||
|
||||
class MemoryStore implements BaseMemoryStore {
|
||||
get: (sid: string, callback: (err: any, session: Express.Session) => void) => void;
|
||||
get: (sid: string, callback: (err: any, session: Express.SessionData) => void) => void;
|
||||
set: (sid: string, session: Express.Session, callback: (err: any) => void) => void;
|
||||
destroy: (sid: string, callback: (err: any) => void) => void;
|
||||
all: (callback: (err: any, obj: { [sid: string]: Express.Session; }) => void) => void;
|
||||
|
||||
Reference in New Issue
Block a user