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;
};
也許他們中的一個是anguarl承諾,另一個是量角器承諾? – Bergi
順便說一句,避免[deferred antipattern](http://stackoverflow.com/q/23803743/1048572)! – Bergi