[英]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.