james.1qwrnewkbjrkwj james.1qwrnewkbjrkwj - 1 year ago 95
Dart Question

Convert simple Dart code to TypeScript

I am trying to set up Hello World, AngularJS 2 app, for the first time.

Here's simple HTML:

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

And the dart code:

class Hello{

String message;

.then((String content) {
Map parsedMap = JSON.decode(content);
message = parsedMap["Message"];

main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();

Could anybody help me convert this Dart code to TypeScript?

Answer Source

Could anybody help me convert this Dart code to TypeScript?


  • typescript has no main.
  • you need to import the stuff you need into typescript
  • has a different naming convention than dart
  • http responses of type applicaiton/json are commonly automatically parsed (objectified).

Based on that :

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

class Hello {

  message: string;

  hello() {
            .then((content) {
              const message = content;



I highly recommend you read a book on TypeScript. I wrote a free one : https://basarat.gitbooks.io/typescript/content/docs/getting-started.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download