[英]File/Blob - eslint(no-undef)
While creating an Apollo Client in a NextJS/TypeScript project, I need to figure out whether the current operation is Upload or not, but ESLint complains that File
and Blob
are not defined.在NextJS/TypeScript项目中创建Apollo Client时,需要判断当前操作是否为Upload,但ESLint报错
File
和Blob
未定义。
I can disable warning: // eslint-disable-next-line no-undef
but I'd like to understand why there's such warning and I'd like to fix it without ignoring if possible.我可以禁用警告:
// 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)
}
You can add browser: true
to your ESLint config file inside the env
prop:您可以将
browser: true
添加到env
属性中的 ESLint 配置文件中:
// .eslintrc
{
"env": {
"browser": true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.