basarat
basarat

Reputation: 275927

Making a module callable

Modules in typescript are compatible with interfaces. e.g. the following is valid:

module M{
    var s = "test"
    export function f(){
        return s;
    }   
}

interface ITest{
    f():string;
}

var x:ITest = M;

However is it possible to have a callable signature in a module? Specifically how can I write a module compatible with the following interface:

interface ITest{
    ():string;
}

Upvotes: 6

Views: 752

Answers (1)

MiMo
MiMo

Reputation: 11953

No, it is not possible. The only entity that can match a call signature is a function

interface ITest{
    ():string;
}

var x:ITest = function() {return "";}
var y:ITest = () => "";

Upvotes: 2

Related Questions