简体   繁体   English

映射函数 - 未处理的 JS 异常:TypeError:undefined 不是评估映射的对象

[英]Map Function - Unhandled JS Exception: TypeError: undefined is not an object evaluating map

I have a file called displayKeyHelpers.ts and the members.map code is on line 118. The code works for most users and in QA as well but occasionally it seems members is undefined.我有一个名为 displayKeyHelpers.ts 的文件, members.map代码在第 118 行。该代码适用于大多数用户和 QA,但有时似乎成员未定义。 I am looking at a crash report that says我正在查看一份崩溃报告,上面写着

displayKeyHelpers.ts, line 118
SIGABRT: Unhandled JS Exception: TypeError: undefined is not an object (evaluating 'n.map') This error is located at: in V in Unknown in Unknown in Unknown..

It seems like members in the function below is undefined.下面的函数中的成员似乎未定义。 How can I add a check?如何添加支票?

export const memberDropdownOptions = (members: any): Option[] => {
  const options: Option[] = []
  members.map((member: Person) => {
    options.push({
      label: `${member.firstName} ${member.lastName}`,
      value: member.dependentNumber,
    })
  })
  return options
}

This is what I tried but it failed some unit tests so I am guessing that it is not right:这是我尝试过的,但它在一些单元测试中失败了,所以我猜这是不对的:

export const memberDropdownOptions = (members: Person[]): Option[] => {
  const options: Option[] = []
  members?.map((member: Person) => {
    options.push({
      label: `${member?.firstName} ${member?.lastName}`,
      value: member?.dependentNumber,
    })
  })
  return options
}

The function is used like this:该函数是这样使用的:

const memberOptions = memberDropdownOptions(members)

The members argument that you are passing to memberDropdownOptions(members) is not defined when the function is being called.您传递给memberDropdownOptions(members)members参数在调用函数时未定义。

Is members relying on some asynchronous logic to be given a value? members是否依赖某种异步逻辑来赋值? Trace back to where it's being assigned a value, and make sure memberDropdownOptions() only fires once it does have one.回溯到它被赋值的地方,并确保memberDropdownOptions()只在它有一个值时才触发。

暂无
暂无

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

相关问题 [未处理的 promise 拒绝:TypeError: undefined is not an object(评估'this.state.result.map')] - [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'this.state.result.map')] 未处理的承诺拒绝:TypeError:未定义不是一个函数,当在react native中为setState映射时会发生'departureloc.map'评估 - Unhandled promise rejection: TypeError: undefined is not a function evaluating 'departureloc.map' occurs when mapping for setState in react native TypeError:undefined不是一个函数(评估“ categories.map”) - TypeError: undefined is not a function (evaluating 'categories.map') TypeError:未定义不是函数(正在评估userItems.map) - TypeError: undefined is not a function (evaluating userItems.map) 未处理的JS异常:TyperError:未定义不是对象(正在评估'_this.onPress.bind') - Unhandled JS Exception: TyperError: undefined is not an object (evaluating '_this.onPress.bind') TypeError:“未定义”不是对象(正在评估“ promise.data.map”) - TypeError: 'undefined' is not an object (evaluating 'promise.data.map') React Native:TypeError:undefined 不是一个对象(评估'_this.props.data.map') - React Native: TypeError: undefined is not an object (evaluating '_this.props.data.map') 错误类型错误:未定义不是 object(正在评估“state.map”) - ERROR TypeError: undefined is not an object (evaluating 'state.map') TypeError: Undefined is not an object(评估'this.state.videos.map') - TypeError: Undefined is not an object (evaluating 'this.state.videos.map') TypeError: undefined is not a function (evaluating 'this.state.list.map') - TypeError: undefined is not a function (evaluating 'this.state.list.map')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM