ducin
ducin

Reputation: 26467

can't get coffeescript-to-typescript to work

I'm migrating a coffeescript app into typescript. There is a coffeescript-to-typescript tool that seems to help a lot with the job. Unfortunately, I can't get it working and the errors thrown seem ridiculous...

This is an example coffee file:

CoreModule.service('FileRequire', [
  # dependencies
  () ->
    @resolver = (subdirectory, extension) ->
      (pathcode) ->
        tmp = pathcode.split ':'
        modules = tmp[0]
        file = tmp[1]
        'app/modules/' + modules.split('/').join('/modules/') + '/' + subdirectory + '/' + file + '.' + extension

    return
])

And this is how I try to execute it (on Windows machine with typescript and coffeescript-to-typescript modules installed globally):

C:\development\mp-frontend>coffee-to-typescript -cma app\modules\core\services\FileRequire.coffee
error compiling app\modules\core\services\FileRequire.coffee
app\modules\core\services\FileRequire.coffee:4:6: error: unexpected TERMINATOR
    @resolver = (subdirectory, extension) ->
     ^
1 files failed

and

C:\development\mp-frontend>coffee-to-typescript -c app\modules\core\services\FileRequire.coffee
Error: spawn tsc ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
    at child_process.js:1137:20
    at process._tickCallback (node.js:355:11)

Can anyone tell me what's going on? The TERMINATOR error seems to be a random error happening with coffeescript, although the application compiles with grunt and works perfetcly fine (it does transpile down to javascript afterall, so the code has to be proper coffee).

The tool seems completely useless so far... please point me on what am I doing wrong.

Upvotes: 1

Views: 326

Answers (2)

MartyIX
MartyIX

Reputation: 28646

I received the same error message as you did. However, it seems that proper installation process for the tool is:

sudo npm install -g coffee-script-to-typescript
sudo npm install -g tsc # This is the step that helped me.

It works for me on Ubuntu 15.04.

Upvotes: 3

basarat
basarat

Reputation: 276085

The tool seems completely useless so far... please point me on what am I doing wrong

I would recommend just compiling the coffescript to JavaScript, and then start using the JavaScript as TypeScript i.e. start adding annotations slowly and migrating to ES6 features like classes.

Upvotes: -2

Related Questions