Samantha J T Star
Samantha J T Star

Reputation: 32758

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

I am using this function:

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

and also this:

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

the parameter q is of type IQuestion

How can I create an interface that represents these function? Note that the getQuestion function does not return anything but the httpGetQuestion returns a promise.

Upvotes: 1

Views: 967

Answers (1)

Radim Köhler
Radim Köhler

Reputation: 123861

This could look like this:

module myModule
{
    export interface IQuestion { ... }

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

The ng.IHttpPromise<T> is a return type representing the $http promise

Upvotes: 1

Related Questions