簡體   English   中英

如何為返回$ http promise的函數創建Typescript接口?

[英]How can I create a Typescript interface for a function that returns an $http promise?

我正在使用此功能:

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。

可能看起來像這樣:

module myModule
{
    export interface IQuestion { ... }

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

ng.IHttpPromise<T>是代表$http承諾的返回類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM