Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

552
Visualizações
An interface can only extend an identifier/qualified-name with optional type arguments. ts(2499)

I am trying to create a new extended interface for express.RequestHandler but this error seems to come up. I cannot understand why.

An interface can only extend an identifier/qualified-name with optional type arguments. ts(2499)

The express.RequestHandler interface does not support async functions. It says

The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>>'?ts(1064)

Here are my interfaces

export interface IRequest extends express.Request {
    user: IUser;
}

export interface IRequestHandler extends RequestHandler = (
    req: IRequest,
    res: express.Response,
    next: express.NextFunction
) => void | Promise<void>;
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It seems you are trying to extend the express.Request interface.

Try:

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

interface IUser {
  name: string;
}

declare module 'express' {
  interface Request {
    user: IUser;
  }
}

const controller = async (req: Request, res: Response, next: NextFunction) => {
  console.log(req.user);
};

enter image description here

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda