0

This is the Javascript version of what I want to do in Typescript, with the important thing to note being the way in which I reference exports.inform from the exports.error function ("exports.inform"):

exports.error = function(_string, _kvp){
    for(var _i = 0; _i < server.clients.length; _++i){
        if(server.clients[_i] != undefined && server.clients[_i].isValid()){
            exports.inform(server.clients[_i], _string, _kvp);
        }
    }
}

exports.inform = function(_client, _string, _kvp){
    var _output = tag + processAll(_string, _kvp);
    _client.printToChat(_output);
}

This is my equivalent in Typescript, but "export function inform" is being referrenced incorrectly within function 'error' ("inform"):

export function error(_str:string, _kvp:Object) {
    for (var _i: number = 0; _i < server.clients.length; ++_i) {
        if (server.clients[_i] != undefined && server.clients[_i].isValid()) {
            inform(server.clients[_i], _str, _kvp);
        }
    }
}

export function inform(_client:Entity, _str:string, _kvp:Object) {
    var _output = tag + processAll(_str, _kvp);
    _client.printToChat(_output);
}

Sorry for the vague explanation, I hope you understand and will try to clarify if it's too hard to comprehend.

Edit: The error it was giving me was 'invalid call signature' caused by performing string concatenations within the argument, which TS apparently does not allow (unless in closed parenthesis), so Ryan's comment was correct: just call inform. Thank you Nypan.

Jexah
  • 183
  • 1
  • 12
  • What do you mean by "referenced incorrectly" ? Is there something wrong with the generated JS (if so, you should post it)? – Ryan Cavanaugh Oct 09 '13 at 05:39
  • No, the method of referencing the inform function from inside the local module is different in Typescript, and I can't figure out how to do it. In regular JS I would call the function: `exports.inform`, by typing `exports.inform`. Now, in the same scenario in TS, I create the function `export function inform`, how do I call it in the same module? – Jexah Oct 09 '13 at 06:17
  • You just call `inform`. – Ryan Cavanaugh Oct 09 '13 at 14:50

1 Answers1

1

I am not entirely sure that i understand your problem or what you are trying to do for that matter. But if i am understanding you correctly the following should work:

module exports {

    export function error(message: string){

        inform(message);
    }

    export function inform(message: string) {

        alert(message);
    }   
}

exports.error("some message");

It might however be better to place the functions in a class like this:

class exports {

    public static error(message: string) {
        exports.inform(message);
    }

    public static inform(message: string) {
        alert(message);
    }   
}

exports.error("some message");

I might misunderstand what you are trying to do.. let me know.

Nypan
  • 6,980
  • 3
  • 21
  • 28