返回表达式类型Promise <t>不能分配给Promise <t>类型?

时间:2016-05-23 15:32:08

标签: javascript jasmine promise protractor angular-promise

当我为下面的函数添加javascript文档时,它会给我一个警告,说明

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

使用下面的return 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 个答案:

答案 0 :(得分:1)

尝试使用更明确的webdriver.promise.Promise代替Promise

@returns {webdriver.promise.Promise<T>}