Creating a module to be called

Modules in typescript are compatible with interfaces. For example, the following is true:

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? In particular, how can I write a module compatible with the following interface:

interface ITest{
    ():string;
}
+5
source share
1 answer

No, It is Immpossible. The only entity that can match the call signature is the function

interface ITest{
    ():string;
}

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

All Articles