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

370
Visualizações
Express + Typescript: Req.status(200) - Type 'Number' has no call signatures

I'm fairly new to typescript and trying to make an Express-server run with it. So I'm basically trying to make the following code run after fetching data with axios:

import express, { Response, Request } from 'express'
(...)
app.get('/api/mk', async (req: express.Request, res: express.Response) => {
    await axios
        .get('http://localhost:8080/rest/kuk/v1/ownerMKKOL/getALL')
        .then((axiosResponse) => {
            const { data } = axiosResponse

            return res.status(200).send(data)
        })
        .catch((err) => err)
})

I'm however getting the following error message and cannot make much sense out of it:

This expression is not callable. Type 'Number' has no call signatures. TS2349

Do I have to extend the Response-interface? If so, what would a possible solution look like?

Any help is much appreciated!

Solution:

I finally found the solution which basically boiled down to a problem with the structure of my project:

Root
|-- React App
    |-- Server
    |   |-- package.json
    |   `-- ...
    `-- package.json
        `-- ...

Somehow when running the build-command from my React App package this problem would appear. I did restructure my project in the following way and the issue did disappear:

Root
|-- Server
|   |-- package.json
|   |-- express.ts
|   `-- ...
`-- Client
    |-- package.json
    `-- ...
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your code, you are awaiting for a promise result, but you're also registering a callback function for a result and a callback for a failure. This will also return a promise, so the code is correct, but you're not returning the value of it and this is leading to the error.

Also, mixing the .then().catch() way with the await syntax is not easy to read. I would change the code this way:

app.get('/api/mk', async (req: express.Request, res: express.Response) => {
    const axiosResponse = await axios
        .get('http://localhost:8080/rest/kuk/v1/ownerMKKOL/getALL');
    const { data } = axiosResponse;
    return res.status(200).send(data);
})

If an exception is thrown, it will be automatically fired and passed to express: it is not strictly necessary to process it, since in your starting code you're not doing anything but throwing it again.

about 4 years ago · Juan Pablo Isaza 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