FLOW:函数调用(无法在空原型对象上调用函数)

时间:2017-05-17 14:44:27

标签: flowtype

有人可以帮我解决导致此错误的原因吗?

这是我的代码。我已经改变了几次,看看我是否能获得预期的覆盖率。

const NO_QUERY = new Error('You need to enter a Query to hit this endpoint')
const axios = require('axios')
class thirdParty {
  headers = {
    Authorization: `secret ${this.secretKey}`
  }
  apiKey = ''
  secretKey = ''
  constructor (apiKey: string, secretKey: string) {
    if (!secretKey) throw NO_SECRET_KEY
    if (!apiKey) throw NO_API_KEY
    this.apiKey = apiKey
    this.secretKey = secretKey
    this.headers = {
      Authorization: `secret ${secretKey}`
    }
    this._request = axios.create({
      headers: {
        Authorization: `secret ${secretKey}`
      }
    })
  }
  productSearch (
    {
      query = ''
    }: {
      query: string
    },
    cb: (error: Error | null, response: ?Object) => void
    ): Promise.resolve<?{ [key: string]: string }> | Promise.reject<Error> {
    if (!cb || typeof cb !== 'function') cb = (error: ?Error | null, response: ?Object) => {}
    return new Promise((resolve:
    Promise.resolve<?{ [key: string]: string }>, reject:
    Promise.reject<Error>):
    Promise.resolve<?{ [key: string]: string }> |
    Promise.reject<Error> => {
      if (!query) return cb(NO_QUERY)
      return axios.get(`<URLENDPOINT>?apiKey=${
        this.apiKey
      }&query=${
        query
      }`, {
        headers: this.headers
      }).then(({ data = {} }: { data: { [key: string]: string } }) => {
        // [flow] function call (Function cannot be called on empty prototype object)
        resolve(data)
        cb(null, data)
      })
      .catch((err: Error) => {
        // [flow] function call (Function cannot be called on empty prototype object)
        reject(err)
        cb(err)
      })
    })
  }
}

如上所述,我在拒绝和解决Promise方法时收到以下错误

[flow] function call (Function cannot be called on empty prototype object)

我必须在这里找到一些给我这个错误的东西,但没有一个非常具有描述性的理由来解决这个错误。

任何帮助将不胜感激

0 个答案:

没有答案