I'm using Express and I'm trying to explicitly define res.locals. In the @types/express package, Express.Response.locals is any, so I can't seem to overwrite it:
types/express/index.d.ts:
declare namespace Express {
interface Response {
locals: {
myVar: number
}
}
}
My Middleware:
import * as express from 'express'
function middleware(
req: express.Request,
res: express.Response,
next: express.nextFunction
) {
res.locals.myVar = '10' // I want this to throw a compiler error
next()
}
I want my wrong assignment of res.locals.myVar to error, but res.locals is still any according to my autocompletion.
How can I remove any and completely replace it?