TypeScript 错误property does not exist on type Object

image.png
image.png
ts刚上手不大熟悉,item.children.map也报错,想知道,children[0]里的name怎么取出来呢

function handleClick(tab:any,event:any) {
      menuList.value?.map(item=>{
        store.dispatch("menu/onelevelTag",formState.activeName)
        if(tab.props.name==item.title){
          router.replace({path: "/storeManage/unifiedPackage"})
          console.log(1111,item["children"][0])
   
          // store.dispatch("menu/add", item.children);
        }
      })
    }
阅读 4.9k
1 个回答

menuList 的类型定义是什么?要么改它,要么后面断言成 any

(item as any)['children'][0];

或者 Record<number, any>Array<any>

(item['children'] as Record<number, any>)[0];
(item['children'] as Array<any>)[0];

都不是好写法,归根结底的问题还是不知道你 item 啥的类型咋定义的,改它才是正确的做法。

P.S. 你这代码里到处是 any 的为啥还非得用 TypeScript,活生生写成了 AnyScript 不就等于没有类型么。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题