在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)
}
答案 0 :(得分:2)
您可以将browser: true
添加到env
属性中的ESLint配置文件中:
// .eslintrc
{
"env": {
"browser": true
}
}