首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >typescript属性“type”在类型“never”上不存在

typescript属性“type”在类型“never”上不存在
EN

Stack Overflow用户
提问于 2019-03-16 04:14:53
回答 1查看 2.2K关注 0票数 0

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

代码语言:javascript
运行
复制
export const getSomething = (actionLog: [] | undefined) => {
  console.info(actionLog[length - 1].type)
}

问题出在哪里?

EN

回答 1

Stack Overflow用户

发布于 2019-03-16 04:15:29

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

代码语言:javascript
运行
复制
export const getSomething = (actionLog: {type: string}[] | undefined) => {
  console.info(actionLog[length - 1].type)
}

更新:

代码语言:javascript
运行
复制
export const getSomething = (actionLog: {type: string}[]) => {
  if (actionLog && actionLog[0]) {
    console.info(actionLog[length - 1].type)
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55190059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档