1

I've tried this, this, etc

// ./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: ts-node@7.0.1 typescript@3.0.1

BrunoLM
  • 97,872
  • 84
  • 296
  • 452

1 Answers1

3

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
3mard
  • 61
  • 4