javascript - Return const -- 期望在箭头函数结束时返回一个值
问题描述
我有一个设置服务的组件,我需要在我的应用程序的其他组件中接收该服务。
这是设置代码:
export const setupRemote = () => {
if (isRemoteAvailable) {
try {
...
const allowAppInstance = SetupConfig.start(remoteInstance);
window.setup = {
someconfig: anothercode,
code: somecode,
};
} catch (e) {
console.error(e);
}
}
};
我需要返回const allowAppInstance,我试图这样做
export const setupRemote = () => {
if (isRemoteAvailable) {
try {
...
const allowAppInstance = SetupConfig.start(remoteInstance);
window.setup = {
someconfig: anothercode,
code: somecode,
};
return {
allowAppInstance
}
} catch (e) {
console.error(e);
}
}
};
但是我不能使用return,在es-lint中会出现这个错误——预计在箭头函数的末尾返回一个值
如何返回此 const 以在我的应用程序的其他部分使用?
解决方案
这里的问题似乎是您没有在 eslint 期望的 catch 块中返回任何内容。请在 catch 块中添加一些 return 并检查函数是否是您的远程实例并采取相应措施。
推荐阅读
- windows-10 - 适用于 linux (WSL) 的 Windows 子系统可以在虚拟桌面中运行吗?
- python - TimeDistributed 与 LSTM 在关键字检测器中
- python - 根据 Pandas 中不同行的其他列中的值比较,将值应用于列
- ios - RxSwift 订阅者接收多个事件
- c++ - 如何优化可变参数模板专业化?
- python - 我在 Pygame 中移动玩家对象时遇到问题
- c - 链表反转有错误
- google-apps-script - 如何获取我收件箱中所有电子邮件的正文并将它们附加到带有 Google Apps 脚本的文档中?
- python - 仅以对 dask 友好的方式基于其中一个数组对两个单独的 xarray DataArrays 进行排序
- arrays - 并行数组元素分配导致 Swift 崩溃