文件/ Blob-eslint(no-undef)

时间:2019-07-01 22:16:58

标签: reactjs typescript eslint apollo next.js

在NextJS / TypeScript项目中创建Apollo客户端时,我需要弄清楚当前操作是否为Upload,但是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 个答案:

答案 0 :(得分:2)

您可以将browser: true添加到env属性中的ESLint配置文件中:

// .eslintrc
{
  "env": {
    "browser": true
  }
}