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

148
Views
give response a type of fetch response in typescript?

I have this in my list.json

[{"id": "1", "qty": 1}]

I call it via fetch

async function fetchPlaces() {
  let response = await fetch(`./data/list.json`);
  response = await response.json();
}

how can make the response same type as the interface?

IList {
   id: string,
   qty: number
}

I tried response = await response.json() as IList[] it doesn't work

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that you are reusing the response variable, which is inferred to be of type Response (which is what fetch returns)

The following works:

interface IList {
   id: string,
   qty: number
}

async function fetchPlaces() {
  let response = await fetch(`./data/list.json`);
  let decoded = await response.json() as IList[]; // type is IList[]
}
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!