What are the main differences between Dart and TypeScript?

13

We've already had a query comparing two languages that run on top of JavaScript .

I think I have missed comparing two languages created for the purpose of creating browser applications and solving JavaScript problems with very different approaches. I chose these two because they have support from major vendors and compete for the attention of programmers.

It's not a goal to close all differences.

    
asked by anonymous 04.02.2015 / 17:55

1 answer

12

Dart is a language created by Google to create great applications. The initial goal was to provide not only a language but also a better infrastructure for developing web applications. But as JavaScript is the lingua franca of the web Dart can only live if stay the same as CoffeScript, TypeScript and other languages did. It generates a JS code that can run in any browser.

Certainly it would have advantages if it could run on its own virtual machine , but market issues prevent this from happening. Still the language was created without concern for compatibility with JS. This may give more power to the language but can create some difficulties with legacy code and interoperability. It shines brighter when you run out of standard web browsers where you can use your own VM.

TypeScript has been created from the beginning not to be a new language, but to add capabilities to the existing JavaScript. Your idea is that all JS code is automatically valid TypeScript code. This limits the language a bit, does not let you solve some problems of JS but is great for interoperability.

TypeScript has added more syntax than semantics to JavaScript. And the differences can be reduced since the JS itself can have new features that the TS has placed. I do not know what the compatibility of this would look like in the future. Perhaps the goal is not to maintain full compatibility forever but only to take advantage of what already exists now.

As TypeScript seems to have more adoption, there are more tools available than Dart. Not only is Microsoft investing heavily in this, but third parties are enduring the language. There is even a lot of community support to generate type annotations for JS libraries that greatly improve interoperability (which is not prevented if you do not have the annotations, just does not provide type checking facilities).

Some features available from TypeScript:

  • optionally static typing;
  • classes, interfaces and mixins ;
  • lambda expressions with simple syntax;
  • modules;
  • enumeration;
  • generics ;
  • optional parameters and values default ;
  • tuples;
  • union types ;
  • type alias;
  • among others.

The language already has a roadmap and several other features will be available.

Dart provides most of these features but in a different way. In addition, the language is already more advanced in other features and has some things that are only possible because syntax compatibility is not necessary. In addition, it provides its own library and better manipulation of the DOM, which was never the goal of TypeScript.

Some of the things that exist in Dart that do not exist in TypeScript:

  • classes and interfaces are more aligned with OOP concepts and have more features;
  • footprint with tree shaking (only pay for what you use);
  • overload operator;
  • real scope;
  • Implicit type conversion only where it makes sense, improving the equality operator;
  • annotations;
  • modules work differently;
  • best use of generics ;
  • reflection;
  • produces better optimizations;
While it is possible to see few differences between the TypeScript and JS code, in fact much of the TS code disappears completely after generating the code something in JS, the JS code generated by Dart differs greatly and has a rather strange structure to it. a programmer follow up. It's hard to tinker with the code generated by Dart but if the programmer wants it after creating and compiling a code in TS he can easily continue to tinker with JS (not that it's interesting).

Conclusion

Apart from the psychological reasons raised by a being from Google, another being from Microsoft, both improve the way to develop great applications. They do not help much to make small scripts . Both add important features to organize large code bases and solve some problems of JS. Dart does this in a more intense and more effective way. TypeScript takes advantage of what already exists.

Dart intends to be an alternative to JavaScript. TypeScript is just a compiler - whose main function is to be a checker - and a type system upon JavaScript. Although both generate JS code as a target.

    
04.02.2015 / 17:55