I am trying to get a TypeScript widget and various guides on how to use node.js and talk about adding properties to the Request object before passing them through middleware.
Of course, for the script type, these properties must be defined, so I tried to do this in the local.d.ts file:
import mySql = require('mysql');
declare module Express {
export interface Request {
dbPool: mySql.IPool;
}
}
Then I will try to call it from my main code file:
...
import express = require('express');
...
var pool = mySql.createPool({
user: "username",
...
});
app.use(function (req, res, next) {
req.dbPool = pool;
});
But I understand: "The" dbPool "property does not exist in the" Request "type." What am I doing wrong?
source
share