mortenma71
mortenma71

Reputation: 1286

coffee -> javascript -> typescript

I'm converting coffeescripts to typescript and have trouble with one simple delay type function.

The coffeescript:

ise.utils.delay = (->
  timer = 0
  (callback, ms) ->
    clearTimeout timer
    timer = setTimeout(callback, ms)
)()

The produced javascript:

  ise.utils.delay = (function() {
    var timer;
    timer = 0;
    return function(callback, ms) {
      clearTimeout(timer);
      return timer = setTimeout(callback, ms);
    };
  })();

When I enter the produced js into a typescript file I get a compile error.

I can't figure out what is wrong.

Upvotes: 0

Views: 215

Answers (2)

mortenma71
mortenma71

Reputation: 1286

I ended up using this:

module ise {
  export module utils {
    var timer = 0;
    export
    function delay(callback, ms) {
      clearTimeout(timer);
      return timer = setTimeout(callback, ms)
    };

... Thanks...

Upvotes: 0

Dick van den Brink
Dick van den Brink

Reputation: 14557

If the above code is all the code you have, then you are missing var ise = { utils: { delay: {}}}

I think what you are actually looking for is modules in TypeScript like below

module ise.utils {
    var timer = 0;
    export function delay(callback, ms) {
        clearTimeout(timer);
        return timer = setTimeout(callback, ms)
    };
}

Upvotes: 2

Related Questions