文件/二进制大对象 - eslint(no-undef)

4
在 NextJS/TypeScript 项目中创建 Apollo Client 时,我需要确定当前操作是否为“上传”操作,但 ESLint 抱怨FileBlob没有定义。
我可以禁用警告:// 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)
}

enter image description here

1个回答

1
你可以在ESLint配置文件中的env属性中添加browser: true来实现浏览器相关的检查:
// .eslintrc
{
  "env": {
    "browser": true
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接