简体   繁体   English

无法将Coffeescript转换为打字稿工作

[英]can't get coffeescript-to-typescript to work

I'm migrating a coffeescript app into typescript. 我正在将coffeescript应用程序迁移到打字稿中。 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): 这就是我如何努力(与Windows机器上执行它typescriptcoffeescript-to-typescript全球安装的模块):

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). TERMINATOR错误似乎是在coffeescript上发生的随机错误,尽管该应用程序以grunt编译并且运行良好(毕竟它确实可以转换为javascript,因此代码必须是合适的咖啡)。

The tool seems completely useless so far... please point me on what am I doing wrong. 到目前为止,该工具似乎完全没用...请指出我做错了什么。

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. 它在Ubuntu 15.04上对我有效。

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 ie start adding annotations slowly and migrating to ES6 features like classes. 我建议只将咖啡脚本编译为JavaScript,然后开始将JavaScript 用作TypeScript,即开始缓慢添加注释并迁移到类的ES6功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM