0

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.

1
  • 1
    But you can tell us what error is, right? Commented Apr 3, 2015 at 13:06

2 Answers 2

2

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)
    };
}
Sign up to request clarification or add additional context in comments.

Comments

0

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.