0

I have a javascript function that I want to convert to typescript. My function returns a promise, but I don't know what type I should put inside the generic promise.

My function:

async function getData(pageNum): Promise<"Here">{
    response = await ((await fetch(`https://reqres.in/api/users?page=${pageNum}`)).json());
    response = response.data;
    return response.map(user => user);
}
arta
  • 25
  • 4
  • what "type" is `response.data;` ... why are you `return response.map(user => user);` ... why not just `return response` ... or `return response.data` instead of `response = response.data` ... or a single line `return (await ((await fetch(`https://reqres.in/api/users?page=${pageNum}`)).json())).data;` since you already have the abomination – Jaromanda X Dec 23 '22 at 05:34
  • Unfortunately, my code is written in such a way that I need these (not all, but I was testing some of them). But thanks for your help, I will try to get rid of the abomination. – arta Dec 23 '22 at 06:05
  • that code as written is not very readable ... my suggestion is to actually split the code into more lines if truth be known ... still ... `return x.map(y=>y)` is redundant ... just `return x` ffs – Jaromanda X Dec 23 '22 at 07:37

0 Answers0