将简单的Dart代码转换为TypeScript

时间:2016-07-05 21:52:41

标签: angularjs typescript dart

我第一次尝试设置Hello World,AngularJS 2应用程序。

这是简单的HTML:

// main thread:
class Worker: public QObject {
    public:
       Worker();

    public slots:

       onInit() {
          // initialize everything
          startTimer(20);
       }

    protected:

       void timerEvent(..) {
          // do your things every 20ms
       }   
  }

  ...

  QThread * pWorkerThread = new QThread();
  pWorkerThread->setObjectName(QString("Serial"));

  Worker * pWorker = new Worker();
  Worker->setObjectName(QString("Common Storage Impl"));
  Worker->moveToThread(WorkerThread);

  connect(pWorkerThread, SIGNAL(started()), pWorker, SLOT(onInit()));
  connect(pWorkerThread, SIGNAL(finished()), pWorker, SLOT(deleteLater()));
  connect(pWorkerThread, SIGNAL(finished()), pWorkerThread, SLOT(deleteLater()));

  pWorkerThread->start();

  ...

飞镖码:

<!doctype html>
<html>
  <body>
    <my-app></my-app>
    <script type="application/dart" src="hello.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>

有人可以帮助我将这个Dart代码转换为TypeScript吗?

2 个答案:

答案 0 :(得分:2)

  

有人可以帮助我将这个Dart代码转换为TypeScript吗?

提示:

  • 打字稿没有main
  • 你需要import你需要的东西到打字稿
  • 具有与dart不同的命名约定
  • 类型applicaiton/json的http响应通常会自动解析(客观化)。

基于此:

import {bootstrap} from "some/angular/module"; 
// Do same for http

class Hello {

  message: string;

  hello() {
        http.getString('/hello')
            .then((content) {
              const message = content;
            });
  }
}


bootstrap(AppComponent);

更多

我强烈建议你阅读一本关于TypeScript的书。我写了一个免费的:https://basarat.gitbooks.io/typescript/content/docs/getting-started.html

答案 1 :(得分:0)

Dart2Ts是一种用于打字稿编译器的高度实验性的飞镖。
https://www.dart-polymer.com/dart2ts/
https://github.com/polymer-dart/dart2ts