passport.js - how to declare typescript interface extension to node request session object? -
in following, returnto
added session object passport methods. how declare interface in typescript?
import express = require('express'); import expresssession = require('express-session'); // how declare presence of returnto, not in underlying type? export function createsession(req: express.request, res: express.response, next: function) { passport.authenticate('local', (err: any, user: userinstance, info: any) => { //. . . req.login(user, (err) => { //. . . res.redirect(req.session.returnto || '/'); }); })(req, res, next); };
there's type declaration express-session
on definitelytyped:
https://github.com/borisyankov/definitelytyped/blob/master/express-session/express-session.d.ts
following pattern in file, can create new d.ts
(call whatever want) containing:
declare module express { export interface session { returnto: string; } }
typescript "merge" property existing definitions.
Comments
Post a Comment