[英]TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined
I have a deeply nested object and I'm trying to get a specific value from it.我有一个深度嵌套的 object,我正试图从中获取特定值。 On my development and production environment, the function returns the error above (TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined.) However, I am unable to debug this, and when I put in the exact same object and function into a code sandbox, it works fine .
在我的开发和生产环境中,function 返回上面的错误(TypeError: Cannot destructure property 'reflectionId' of 'undefined' as it is undefined.)但是,我无法调试它,当我输入完全相同的 object和 function 进入代码沙箱,它工作正常。
I have recreated my object and code in a codesandbox here: https://codesandbox.io/s/nameless-bird-rknxrr?file=/src/index.js:28281-28461 (check the console to see the working output)我在此处的代码箱中重新创建了我的 object 和代码: https://codesandbox.io/s/nameless-bird-rknxrr?file=/src/index.js:28281-28461 (检查控制台以查看工作输出)
const discordLink = CHARACTER_MAP
.flatMap((character) => character.chapters)
.find(({ reflectionId }) => reflectionId === reflectionNum).discordLink;
What could the problem be?可能是什么问题? The flatMap returns a properly formatted object (checked that).
flatMap 返回格式正确的 object(已检查)。
reflectionId
is the property name I am looking for, and it seems correctly defined in both my live code and the sandbox. reflectionId
是我正在寻找的属性名称,它似乎在我的实时代码和沙箱中都正确定义了。 Based on how.find() is described in [the Mozilla docs] 1 it seems like I'm using the "Using arrow function and destructuring" method properly too.根据 [Mozilla 文档] 1中描述的 how.find() ,我似乎也在正确使用“使用箭头 function 和解构”方法。 It's most puzzling that it works in codesandbox but not in live.
最令人费解的是,它在 codesandbox 中有效,但在 live 中无效。
Try this:尝试这个:
const discordLink = CHARACTER_MAP
.flatMap((character) => character.chapters)
.find((reflection) => reflection.reflectionId === reflectionNum).discordLink
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.