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

时间:2019-03-15 20:14:53

标签: typescript

我在代码中遇到打字错误typescript Property 'type' does not exist on type 'never'

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

出了什么问题?

1 个答案:

答案 0 :(得分:0)

解决方案是为'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)
  }
}
相关问题