简体   繁体   English

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

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

I have the typescript error typescript Property 'type' does not exist on type 'never' in the code 我有打字稿错误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)
}

What is the issue? 有什么问题?

The solution is to define type for 'type' property: 解决方案是为'type'属性定义类型:

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

UPDATED: 更新:

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