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

278
Visualizações
Axios GET returns a string which is an object

I have built a function that sends an axios Request. I use typescript and don't want to use any as the return data types of the function and the axios request itself.

The problem is, however, that the object that comes back contains the params id, which in turn is an object. Honestly, I have never seen such an object. I do not even know what kind of an object that is. Maybe it is some basic stuff which I never heard about. It is pretty difficult to make a good google search regarding that.

I want to create an typescript interface out of it. I do not even have a good idea to start.

Would appreciate any help

this is a small part of the return object:

 {
          data{
           '12345': { // params.id --> causing my poblem
                   address: {
             ...,
        }}}
    }
 

Thats my function

async function getData (): Promise<IReturnData[]> {
const {data} = await axios.get<IReturnData>(`....${id}`) // in our case 12345
return Object.entries(data.data)[0];

}

How should I build IReturnData ?

    export interface IReturnData {
      data {
          string: { adress: Adress......
    }}}
   

    or 
    export interface IReturnData {
      data  {
          "1234 but that will change on every request": {
             adress: Adress......
     }}}
        
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the best you can do is using Mapped Types.

But it's not perfect, see the example below, or this playground...

interface MyModel {
    [key: string]: Address;
}

const goodExample: MyModel = {
    "12345": {
        country: "Germany"
    }
}

const badExample: MyModel = { // Sadly this also works, but I don't think there is a way to limit it to one key
    "12345": {
        country: "Germany"
    },
    "23456": {
        country: "Germany"
    }
}
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