【发布时间】:2019-11-12 13:11:39
【问题描述】:
在 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)
}
【问题讨论】:
标签: reactjs typescript eslint apollo next.js