如何为返回$ http承诺的函数创建Typescript接口?

时间:2014-07-21 17:05:36

标签: angularjs typescript

我正在使用此功能:

function httpGetQuestion(q) {
    return $http({
        url: '/api/Question/GetByUId/' + q.questionUId + '/fetch',
        method: "GET"
    })
}

还有这个:

test.getQuestion = function (q) {
    getQuestion(q);
}

参数q的类型为IQuestion

如何创建代表这些功能的界面?请注意,getQuestion函数不返回任何内容,只是httpGetQuestion返回一个promise。

1 个答案:

答案 0 :(得分:1)

这可能是这样的:

module myModule
{
    export interface IQuestion { ... }

    export interface IMyService
    {
        httpGetQuestion(): ng.IHttpPromise<IQuestion>
        getQuestion() : void
    }
}

ng.IHttpPromise<T>是表示$http承诺

的返回类型