webstorm bugs using NestJs LoggerMiddleware

I'm trying to configure the NestJs Logger class, but the IDE throws me this errors:

- Unresolved function or method get() 

- Unresolved function or method on() 

- Method expression is not of Function type 

 

I've already have installed the @types/express but the errors are still there.

The project seems to run and work fine, how can I fix these bugs or what am I missing to configure or installl inside the project?

Thanks

0

Can't reproduce with

import {NextFunction, Request, Response} from "express";

class Test {
use(req: Request, res: Response, next: NextFunction) {
const agent = req.get('')
res.on('finish', () => {
})
next()
}
}

 

Could you share a code snippet (as text) or a sample project that reproduces the issue?

0

Hi, sure, here's the code snippet:

By the way, I'm using the latest version of WebStorm

import { Injectable, Logger, NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
private logger: Logger = new Logger('HTTP');

use(req: Request, res: Response, next: NextFunction): void {
const { method, originalUrl } = req;

res.on('finish', () => {
const { statusCode } = res;
this.logger.log(`${method} [${statusCode}] - ${originalUrl}`);
});
next();
}
}
0

Thanks! Works fine for me when using your snippet (the latest Webstorm version):

Could you check if you can reproduce the issue in a new project?

0

I reproduced the exact same code on a different project using the webstorm's NestJs template and the issue didn't appear.

Do you have any idea of why this could have happen?

0

Mare sure that the node_modules folder is included in index. If this doesn't help, it must be a problem with project dependencies (there might be some conflicts)

0

请先登录再写评论。