What are the main differences between Dart and Typescript?

Asked

Viewed 1,733 times

16

We already had a question comparing two languages that run on top of Javascript.

I think it was necessary to compare two languages created for the purpose of creating applications for browsers and solving Javascript problems with very different approaches. I chose these two because they are supported by large suppliers and compete for the attention of programmers.

It is not objective to try to close all differences.

1 answer

15


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 it stays the same as Coffescript, Typescript and other languages did. It generates a JS code that can run in any browser.

How every new technology needs a killer application to avenge, and more recently Flutter was created with her, as it fell into the people’s taste Dart finally began to be used.

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

Typescript has been created since the beginning not to be a new language, but to add capabilities to existing Javascript. Your idea is that every JS code is automatically a valid Typescript code. This limits the language a little, does not solve some problems of JS but is great for interoperability.

Typescript added more syntax than semantics to Javascript. And the differences can be reduced since the JS itself may have new features that the TS put in. I don’t know what the compatibility of this would look like in the future. Maybe the goal is not to maintain full compatibility forever but just take advantage of what already exists now.

Since 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 supporting the language. There’s even a lot of community support to generate type annotations for JS libraries several that greatly improve interoperability (which is not prevented if it does not have the annotations, only does not provide type verification facilities).

Some features available from Typescript:

  • optionally static typing;
  • classes, interfaces and mixins;
  • expressions lambda with simple syntax;
  • modules;
  • enumeration;
  • Generics;
  • optional and value parameters default;
  • tuples;
  • Union types;
  • alias of types;
  • among others.

The language already has one roadmap and various other resources will be made available.

Dart provides most of these resources but in a different way. Besides this 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 DOM manipulation, 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;
  • bass Footprint through Tree Shaking (only paid for what you use);
  • Overload operator;
  • real scope (now even JS has);
  • 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 Typescript and JS code, in fact much of the TS code disappears completely after generating something in JS, the JS code generated by Dart differs quite a bit and has a somewhat strange structure for a programmer to follow. It is difficult to fiddle with the code generated by Dart but if the programmer wants after creating and compiling a code on TS he can easily continue fiddling with JS (not that it is interesting).

Completion

Apart from the psychological reasons raised by one being from Google, another being from Microsoft, both improve the way to develop large applications. They don’t help much to make small scripts. Both add important resources to organize large code bases and solve some JS problems. Dart does this more intensely and effectively. Typescript takes advantage of what already exists.

Dart is intended to be an alternative to Javascript. Typescript is just a compiler - whose main function is to be a checker - and a type system on top of Javascript. Although both generate JS code as a target.

Time passed, Dart was repositioned and Flutter saved him, today the language is used to make customers in general ways.

The two languages have received many updates in recent years and they have improved a lot, some of the evaluations made in 2015 are no longer worth 2020.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.