Reputation: 100381
// ./typings/express/index.d.ts
declare namespace Express {
export interface Request {
token?: string
}
}
Example usage:
import * as express from 'express'
(req: express.Request, res: express.Response, next: express.NextFunction) => {
const foo = req.token
}
It does work if I compile directly (tsc -p .
), it does work in Visual Code, but when I try to run with ts-node
I always get:
error TS2339: Property 'token' does not exist on type 'Request'.
Any idea how can I make it work with ts-node?
Versions: [email protected]
[email protected]
Upvotes: 1
Views: 584
Reputation: 61
The only workaround that worked for me was enabling the files flag
ts-node --files index.ts
and for mocha
TS_NODE_FILES=true mocha
Upvotes: 3