reactjs - 文件/Blob - eslint(no-undef)
问题描述
在 NextJS/TypeScript 项目中创建 Apollo 客户端时,我需要确定当前操作是否为 Upload,但 ESLint 抱怨File
并Blob
没有定义。
我可以禁用警告:// eslint-disable-next-line no-undef
但我想了解为什么会有这样的警告,如果可能的话,我想在不忽略的情况下修复它。
const isFile = (value: any): boolean => {
if (isPlainObject(value) || Array.isArray(value)) {
return Object.values(value).map(isFile).includes(true)
}
const isfile = typeof File !== 'undefined' && value instanceof File
const isblob = typeof Blob !== 'undefined' && value instanceof Blob
return isfile || isblob
}
const isUpload = ({ variables }: any) => {
return Object.values(variables).some(isFile)
}
解决方案
你可以在 props 中添加browser: true
到你的 ESLint 配置文件中env
:
// .eslintrc
{
"env": {
"browser": true
}
}
推荐阅读
- android - 在 Android Recycler View 中使用 Intent 共享图像
- google-apps-script - 联系人导入失败
- javascript - 使用 TypeScript 时 PhpStorm 警告 Vue 组件中的 Object 方法
- react-native - 设置 ReactNative 状态的问题
- php - 只有当它跟随一个数字时,如何从字符串中删除一个字符?
- python - “RuntimeError:给定组=1,大小为 [6, 1, 3, 3] 的权重,预期输入 [10, 3, 28, 28] 有 1 个通道,但有 3 个通道
- android - 在 Concat RecyclerView 适配器中,我们可以水平显示第一个适配器的数据,然后垂直显示下一个适配器的数据吗?
- c# - 当 WPF ListView 仅包含折叠项时,将其行高缩小为零
- git - 重命名未发布的 NPM 包
- javascript - Angular如何从通过绑定的兄弟组件调用方法
?