Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!