Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a module callable

Tags:

typescript

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;
}
like image 650
basarat Avatar asked Mar 18 '13 04:03

basarat


1 Answers

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 = () => "";
like image 107
MiMo Avatar answered Sep 28 '22 09:09

MiMo