It is possible that I may have overlooked specifying the return type in this function. However, I am unsure of how to adjust it. Please help me preserve the original function while migrating it to TypeScript. Your assistance and insights are greatly appreciated :)
const arrayPromise: Promise<string[]> = new Promise<string[]>((resolve, reject) => {
// Requesting elements: depAirportId, arrAirportId, depPlandTime // Choose a specific airline using &airlineId=AAR
axios.get(url)
.then((res:any) => {
// ! Not all code paths return a value.ts(7030)
const item = res.data.response.body.items.item
this.state.totalCount = res.data.response.body.totalCount
if(this.state.totalCount < 1)
return this.state.noTicket
this.state.depTime = res.data.response.body.items.item.forEach((obj:any) => {
/* Using interpolation allows for function usage (as no interference with object properties) */
obj.depTime = `${obj.depPlandTime}`.slice(-4, -2)
/* Object.values: converts each object into an array */
return Object.values(obj)
})
this.state.depMin = res.data.response.body.items.item.forEach((obj:any) => {
obj.depMin = `${obj.depPlandTime}`.slice(-2)
return Object.values(obj)
})
this.state.arrTime = res.data.response.body.items.item.forEach((obj:any) => {
obj.arrTime = `${obj.arrPlandTime}`.slice(-4, -2)
return Object.values(obj)
})
this.state.arrMin = res.data.response.body.items.item.forEach((obj:any) => {
obj.arrMin = `${obj.arrPlandTime}`.slice(-2)
return Object.values(obj)
})