Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a void JQueryPromise in typescript?

I'm having trouble understanding the type for a JQueryPromise. I'd like my promise to be of type void, but while the interface definition accepts a void I don't know how to return/cast the promise to match the interface signature. When I compile I get the error:

Call signatures of types '() => JQueryPromise<{}>' and '() => JQueryPromise' are incompatible.

Here's a sample of the code:

module Sample {
    export interface Ifoo {
        bar: () => JQueryPromise<void>;
    }

    export class fooClass implements Ifoo {
        bar() {
            var result = $.Deferred();
            // logic
            return result.promise();
        }
    }
}

What am I doing wrong; or what could I be doing right?

Thanks!

-John

like image 829
JohnKoz Avatar asked Aug 14 '14 12:08

JohnKoz


1 Answers

Use <void> when creating the defferred:

module Sample {
    export interface Ifoo {
        bar: () => JQueryPromise<void>;
    }

    export class fooClass implements Ifoo {
        bar() {
            var result = $.Deferred<void>();
            // logic
            return result.promise();
        }
    }
}
like image 170
basarat Avatar answered Oct 18 '22 00:10

basarat