I tried to put this script to increase the security of the system but it gave error with the typescript, in this case, I tried to put it in the app.ts
obs: this code was an attempt to convert a script in nodejs to typescript
script
import express from 'express';
import helmet from 'helmet';
import redis from 'redis';
import RateLimit from 'express-rate-limit';
import RateLimitRedis from 'rate-limit-redis';
import { resolve } from 'path';
import routes from './routes';
import ErrorHandler from './app/middlewares/errorHandler';
class App {
public server = express();
constructor() {
this.middlewares();
this.routes();
this.errorHandlers();
}
middlewares() {
this.server.use(express.json());
this.server.use(helmet());
if (process.env.NODE_ENV === 'production') {
this.server.use(
new RateLimit({
store: new RateLimitRedis({
client: redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
}),
}),
windowMs: 1000 * 60 * 15,
max: 100,
}),
);
}
}
region with error
new RateLimit({
store: new RateLimitRedis({
client: redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
}),
}),
windowMs: 1000 * 60 * 15,
max: 100,
}),
message of error
‘new’ expression, whose target lacks a construct signature, implicitly has an ‘any’ type.
2
Answers
You should add type descriptions for those packages:
This goes to all other install packages as well. If you have a package that does not have a corresponding type definitions package then you should create it yourself.
I believe if you change from
to
Will fix the issue.