簡體   English   中英

文件/Blob - eslint(no-undef)

[英]File/Blob - eslint(no-undef)

在NextJS/TypeScript項目中創建Apollo Client時,需要判斷當前操作是否為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)
}

在此處輸入圖片說明

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM