dart2ts 0.0.1

  • README.md
  • Installing
  • Versions
  • 50

Dart2Ts : a better TS interface


Dart2Ts is an highly experimental dart to typescript compiler.

Why ?

Because I'm tired of the current limits of dartdevc. Also translating dart to TS allows us to leverage the tsc to produce code that works on every browser and optimizing, ecc.


  • obviously : semantic equivalence
  • Produce "natural" and readable TS code, just like how you would have written that same code in TS.
  • Make it simple to use that code from TS and vice versa, like:
    • Allow extending a dart2ts class from ts and vice versa.


  • main target is to make it work on web, so:
    • initially don't want to port any "platform specific" library, try to use only @JS
    • I don't care about Isolate and stuff like that

What works

At the moment only translating e2e_test project, that means:

  • basic function definition

  • invocation

  • import of other modules (only core and current package for now)

  • string interpolation

  • named constructors

  • class extension

  • calling named constructors

  • basic class definition

  • basic instance creation

  • named parameters

  • optional parameters

  • cascading

  • (cond)?true:false conditional expressions

  • this implicit reference for method invocation

  • calling .first psuedo accessor on a List (it's replaced by an extension method)

  • property

  • property accessor

  • top level variable

  • redir constructors

  • field initializers

  • field parameters

  • properties initializers

  • support for @JS annotation

    • DART2TS extension

note 'e2e_test' project is now able to write on the HTML page !!!

UPDATE : now even package:html5 is compiling. Next step is to create a demo project using package:html5 and demo it.

Dart2TS extensions

Estension to @JS annotation

@JS can now be used to specify from which module the symbol should be loaded. Module path and name should be separated by the '#' character. Alternatively one can use the @Module('modulepath') to specify the module path and the @JS('name') annotation for the namespace only. When both ('#' char and @Module annotation) are used the latter wins. The final name is defined concatanating both module path and namespace path information from each enclosing element. For example

libary mylib;

class That {


libary mylib;

class That {

Will cause any reference to That to be translated as a reference to myjslib.Thing in module module/submod.

To declare only the module and not a namespace use @JS('module#'). For example the following will associate the $ top level variable to the $ symbol exported by module jquery:

library mylib;

Function $;


library mylib;

Function $;

@JS annotation can also be used to change the name of the corresponding native method or properties, thus allowing to resolve any name conflict between dart and TS (Notably the is static method inside a class used by polymer).


  • a better way to deal with @anonymous @js objects. For instance "new ShadowRootInit()" should become ="{mode:null,delegatesFocus:null}" or something like that.
  • using other libraries (easy)
    • declare dep on both pubspec.yaml and package.json
    • build the dep and produce typelibs and js
    • when main project is built the already compiled is used for runtime and the dart as analysis
      • dart could be replaced by summaries or by generated "dart type lib" : a version of the original lib with only external declarations.
  • dart "typelibs" (libs with only declaration and all method declared external) (boring)
  • make class definition work (easy)
  • flow control statemets (easy)

    • for in
    • for (x;y;z)
    • yield
    • return
    • while
    • do
    • ecc.
  • exports (medium ? easy ?)

  • nullable expression (?? operator ?= operator) (super easy)

  • literals

    • array
    • map
  • symbol (map to symbol)

  • complete expression (boring)

    • whats missing ?
  • factory constructors (super easy)

  • async, async* (should be easy as TS supports 'em all)

    • map Future to Promise (difficulty level ?!?)
  • manage scope reference to "this." things (boring)

  • mixin (with polymer approach) (should be easy but no named constructor should be allowed)

  • implements (subtle , typescript implement of classes is the same of dart?)

  • deal with "rewriting" some method calls, like : (tricky)

    • List -> Array
    • Map<String,?> -> {}
  • deal with "@JS" things (easy)

  • (light) dart_sdk port

    • collections (maybe tricky, expecially to maintain semantical compatibility)
    • package:html (easy)
    • what else ? (boh)


Dart2TS generated classes do not requires a top common class so it will be easy to implement native js classes extensions. DDC infact requires a new initializers on super classes otherwise it will complain in some circumstances (that's why we had to patch id in polymerize).


When executed a second time it can throw. Probably a bug in builder package. A workaround is to remove the .dart_tool hidden folder inside the package folder you are building (it will be recreated in the next build).

When launching dart2ts with the watch flag (-w) there's no problem.

Use this package as an executable

1. Install it

You can install the package from the command line:

$ pub global activate dart2ts

2. Use it

The package has the following executables:

$ dart2ts

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dart2ts: "^0.0.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:dart2ts/dart2ts.dart';
Version Uploaded Documentation Archive
0.0.1 Oct 31, 2017 Go to the documentation of dart2ts 0.0.1 Download dart2ts 0.0.1 archive


We analyzed this package on Jul 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
20 / 100
Code health derived from static analysis. [more]
83 / 100
Reflects how tidy and up-to-date the package is. [more]
74 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, other

Primary library: package:dart2ts/dart2ts.dart with components: io, build.


  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Use constrained dependencies.

    The pubspec.yaml contains 3 dependencies without version constraints. Specify version ranges for the following dependencies: args, build_runner, source_gen.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 errors 13 hints.

    Strong-mode analysis of lib/src/code_generator.dart failed with the following error:

    line: 38 col: 3
    Invalid override. The type of 'Dart2TsBuildCommand.run' ('() → void') isn't a subtype of 'Command<bool>.run' ('() → FutureOr<bool>').

    Strong-mode analysis of lib/src/deps_installer.dart failed with the following error:

    line: 44 col: 3
    Invalid override. The type of 'Dart2TsInstallCommand.run' ('() → void') isn't a subtype of 'Command<bool>.run' ('() → FutureOr<bool>').

    Similar analysis of the following files failed:

    • lib/src/commands.dart (hint)
    • lib/src/overrides.dart (hint)
    • lib/src/utils.dart (hint)
  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use dart2ts.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
analyzer ^0.30.0 0.30.0+4 0.32.3
args any 1.4.3
build ^0.10.0 0.10.2+1 0.12.7
build_runner any 0.5.0 0.9.1
source_gen any 0.7.5+1 0.8.3
Transitive dependencies
async 1.13.3 2.0.7
barback 0.15.2+16
build_barback 0.4.0+1 0.5.0+4
charcode 1.1.2
cli_util 0.1.3
code_transformers 0.5.1+5
collection 1.14.10
convert 2.0.1
crypto 2.0.6
csslib 0.14.4
dart_style 1.0.9+1 1.1.2
front_end 0.1.0-alpha.4.1 0.1.3
glob 1.1.6
html 0.13.3+1
http_parser 3.1.2
isolate 1.1.0 2.0.1
kernel 0.3.0-alpha.1.1 0.3.3
logging 0.11.3+1
meta 1.1.5
mime 0.9.6+1
package_config 1.0.3
path 1.6.1
plugin 0.2.0+2
pool 1.3.5
shelf 0.7.3+2
source_maps 0.10.6
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.7+1
stream_transform 0.0.14
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+9
yaml 2.1.14