I'd like to extend Express' Request interface to include user information. This is common and has been asked here before, so I've been able to accomplish it with the following:
import { IHttpUser } from './user.interface';
declare module "express" {
export interface Request{
user?: IHttpUser;
}
}
Great - that works. Without having to use any imports I can just go req.user wherever I am and I have typing information for it.
From what I understand using module
is not the recommended way to do this. I should be using namespace
. So I'd like to be able to go:
import { IHttpUser } from './user.interface';
declare namespace Express {
export interface Request{
user?: IHttpUser;
}
}
...but I can't because if you have an import
at the top this won't be picked up as being available globally (I apologize I don't know the correct terminology here).
So what is the "correct" way to do this? It works like I have it, but since I'm supposed to move to using namespace
I'd like to learn that way.