[英]File/Blob - eslint(no-undef)
在NextJS/TypeScript项目中创建Apollo Client时,需要判断当前操作是否为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)
}
您可以将browser: true
添加到env
属性中的 ESLint 配置文件中:
// .eslintrc
{
"env": {
"browser": true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.