2016-05-23 122 views
1

當我添加的JavaScript文檔爲以下功能,它會給我一個警告說,返回表達式類型Promise <T>不可分配給類型Promise <T>?

Return expression type Promise<T> is not assignable to a type Promise<T> 

這有什麼錯用下面的迴歸defer.promise還是我把return語句在一個錯誤的地方?

/** 
    * 
    * @param zname 
    * @returns {Promise<T>} 
    */ 
    this.setInfoFromAPI = function (name) { 
     var defer = protractor.promise.defer(); 
     var controlFlow = protractor.promise.controlFlow(); 
     httpRequestUtility.getRestfulAPIToken().then(function (accessToken) { 
      console.log("Access Token is " + accessToken); 
      controlFlow.wait(
       getInfoFromAPI(accessToken, name).then(function (returnData) { 
        if (String(returnData).match(httpStatusCodeClientErrorRegx)) { 
         defer.reject('Get Request Error for Zone Info\nResponse Error Code - ' + returnData); 
        } else { 
         setUpInfoFromAPI(returnData); 
         defer.fulfill(); 
        } 
       }), 60000, 'Get Information').then(function() { 
      }) 
     }); 
     return defer.promise; 
    }; 
+1

也許他們中的一個是anguarl承諾,另一個是量角器承諾? – Bergi

+2

順便說一句,避免[deferred antipattern](http://stackoverflow.com/q/23803743/1048572)! – Bergi

回答

1

嘗試使用Promise更加明確webdriver.promise.Promise代替:

@returns {webdriver.promise.Promise<T>} 
相關問題