繁体   English   中英

typescript属性'type'在'never'类型上不存在

[英]typescript Property 'type' does not exist on type 'never'

我有打字稿错误typescript Property 'type' does not exist on type 'never'在代码中的typescript Property 'type' does not exist on type 'never'

export const getSomething = (actionLog: [] | undefined) => {
  console.info(actionLog[length - 1].type)
}

有什么问题?

解决方案是为'type'属性定义类型:

export const getSomething = (actionLog: {type: string}[] | undefined) => {
  console.info(actionLog[length - 1].type)
}

更新:

export const getSomething = (actionLog: {type: string}[]) => {
  if (actionLog && actionLog[0]) {
    console.info(actionLog[length - 1].type)
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM