typescript 如何在箭头函数中存储数据?

olhwl3o2  于 2023-01-18  发布在  TypeScript
关注(0)|答案(1)|浏览(126)

这是我的arrow函数,我把它存储在let s arrow函数中,我把它存储在一个循环中,并合并了object.assign中的所有对象。但是,当我运行let s arrow函数时,我得到了一个Promise { undefined }错误。

let s = async() => {
  Object.values(sqlQuery).map(async(o:any) => {
    a.map(async(k:any) => {
      c.map(async(l:any) => {
        var district:any = `select slug from foa_section_content where foa_section_content_id IN (${k})`;
        var [district1]: any = await connection.execute(district);
        var commune:any = `select slug from foa_section_content where foa_section_content_id IN (${l})`;
        var [commune1]: any = await connection.execute(commune);

        s = await (Object.assign(o,{district1},{commune1}))
   
                  })
    })
    
  })
}
    return (s());
xesrikrc

xesrikrc1#

问题是您没有从箭头函数返回值。箭头函数的语法为:

let s = async() => {
  return Object.values(sqlQuery).map(async(o:any) => {
    a.map(async(k:any) => {
      c.map(async(l:any) => {
        var district:any = `select slug from foa_section_content where foa_section_content_id IN (${k})`;
        var [district1]: any = await connection.execute(district);
        var commune:any = `select slug from foa_section_content where foa_section_content_id IN (${l})`;
        var [commune1]: any = await connection.execute(commune);

        return Object.assign(o,{district1},{commune1});
   
                  })
    })
    
  });
}

相关问题