본문 바로가기

error records

[No overload matches this call] is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

반응형

 

[No overload matches this call] 

~ is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

 

TS2769: No overload matches this call.   The last overload gave the following error.     Argument of type '(req: Request, res: Response, next: NextFunction) => any' is not assignable to parameter of type 'RequestHandlerParams<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.       Type '(req: Request, res: Response, next: NextFunction) => any' is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.         Types of parameters 'req' and 'req' are incompatible.           Type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is missing the following properties from type 'Request': cache, credentials, destination, integrity, and 13 more.

 

 

미들웨어를 만들고 해당 함수를 불러오려고 했더니 위와 같은 오류가 나왔다. type 에러! 

-> 불러오는 함수쪽 인자값에 타입 중 Request가 express 에서 가져온게 아니었다. 

 

As the explanation said, it was a Type error, I found out the type of "req" was not from "express". 

 

import { NextFunction, Response } from 'express';

const checkAA = (req, res, next) => {
  return next();
};

const exec = (req: Request, res: Response, next: NextFunction): any => {
    checkAA(req, res, next);
  };

export default { exec };

 

여기에서 req의 type이 express.Request 가 아니어서 에러가 났다. 

아래와 같이 가져오니 에러가 나지 않는다! 

 

You have to use express.Request instead of Request.  It can be fixed like below and it works like a charm

 

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

 

반응형