【问题标题】:File/Blob - eslint(no-undef)文件/Blob - eslint(no-undef)
【发布时间】:2019-11-12 13:11:39
【问题描述】:

在 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)
}

【问题讨论】:

    标签: reactjs typescript eslint apollo next.js


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-12-27
      • 2018-07-13
      • 2017-10-08
      • 2017-10-29
      • 2023-03-12
      • 2021-02-28
      • 1970-01-01
      • 2019-04-19
      相关资源
      最近更新 更多