19

I'm working on a large code base that could benefit from Typescript, but since eventually the world will be moving to ES6, should I steer the development towards Traceur?

I don't want to change Typescript implementations in order to target ES6 (when is ready), so my feeling now is to go ahead with Traceur.

Can anyone advise?

Nikos
  • 7,295
  • 7
  • 52
  • 88
  • Are you interested in ES6 language features, or in type safety? TypeScript can provide compile-time type safety, whereas ES6 has no such concept. – Jean-Philippe Pellet May 14 '14 at 15:54
  • @Jean-PhilippePellet As of Q3 2014 I've went back to using TypeScript as I missed compile-time safety too much. – Nikos Aug 08 '14 at 14:24
  • @Jean-PhilippePellet: nit-pick: TypeScript is very useful, but it does not actually provide type safety in any meaningful sense of the word. – Andreas Rossberg Nov 02 '14 at 09:25
  • @AndreasRossberg I'm not sure I dare contradict you after having a look at your profile, but what would you then call preventing a multiplication on strings, for instance? – Jean-Philippe Pellet Nov 02 '14 at 15:11
  • @Jean-PhilippePellet, TS does not prevent that, at least not in the general case. It's type system isn't _sound_, so even expressions of type `number` can potentially evaluate to a string. As I said, I was nit-picking, but the usual definition of type safety would require soundness. – Andreas Rossberg Nov 02 '14 at 15:52
  • @AndreasRossberg Interesting. I know how the failure to handle co- and contravariance in generics and in function types makes the type system unsound, but I'm surprised at how far you go in saying that TS's compile-time type safety is inexistant. – Jean-Philippe Pellet Nov 03 '14 at 09:45
  • 1
    @Jean-PhilippePellet, oh, there are plenty of other things that break soundness in TS. For example, subtyping on (mutable) objects: `var x: {a:number} = {a: 0}; var y: {a:Object} = x; y.a = "boo"; x.a * 2`. – Andreas Rossberg Nov 03 '14 at 13:22
  • @AndreasRossberg Hmm, right. Thanks for the example and for the explanation. Does Dart (or another language designed to compile to JS) have a sound type system? – Jean-Philippe Pellet Nov 03 '14 at 14:38
  • @Jean-PhilippePellet, there are few languages _without_ a compiler to JS these days, see https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js -- so some should be type-safe, but how usable most of them are I cannot say. Dart certainly is unsound. There also is Safe TypeScript from MSR, but that's more of a research project. – Andreas Rossberg Nov 03 '14 at 15:08

6 Answers6

30

I definitely do not agree with the opinion that TypeScript and Traceur are so different, TypeScript is ES5 with types and Traceur is just about ES6.

On the one hand there is an ES6 compatible TypeScript 2.0 in progress. On the other hand there are a couple of features in Traceur marked as experimental in docs, namely types and annotations. And it turns out that types are very similar to the TypeScript types whereas annotations are something irrelevant both to ES6 and TypeScript. So Traceur is more just ES6 and there is already name for that: AtScript. Yes, we have another language extension :-)

There is a nice slide from Miško Hevery presentation that shows what is really going on here, fully valid as soon as TypeScript 2.0 is released:

AtScript and TypeScript as ES6 extensions

So whatever you decide to use, it is important to note: they are subsets, you may write ES5/ES6 JS and it will be valid TypeScript code, you may write TypeScript and it will be valid AtScript code.

Turning back to your question, I would give the humble advise to start with ES6 using Traceur with experimental features turned off (it is pretty stable now) and extend as needed, because this is not so radical a decision, doesn't lock you in and leaves space to move in the future.

UPD: At the beginning of the 2015 I would also recommend to pay attention to 6to5 project (renamed to Babel) as an alternative to Traceur. It moves very fast and provides has some nice features, such as readability of generated code and better support for node.js and build systems.

Kevin Montrose
  • 22,191
  • 9
  • 88
  • 137
Thaumant
  • 2,113
  • 2
  • 19
  • 14
  • 9
    UPD2: AtScript and Typescript are merging, as announced at the [ng-conf 2015](https://twitter.com/ngconf/status/573521849780305920) so you will get benefits of both with Typescript :) also Typescript will be used to create Angular 2 meaning it will be adopted by another big project – Lski Mar 08 '15 at 18:57
  • 6
    UPD3: 6to5 project is defintely worth watching but has been renamed to [Babel](https://babeljs.io) just recently – Lski Mar 08 '15 at 19:01
  • Not all ES5 code is valid TypeScript, despite this oft-made claim. `function testFunc(a, b) { console.log(a); } testFunc('hello'); /* error */ testFunc('hello', 'goodbye', 'go away'); /* error */` – bradw2k Mar 02 '16 at 17:50
12

TypeScript and Traceur have completely different goals and aren’t comparable in the way you are trying to compare them.

TypeScript is a superset of EcmaScript that adds strict typing. It includes some features from ES6, but its primary goal is to add strict typing to the language (while aligning with ES6), not to provide ES6 support.

In contrast, Traceur is a future-EcmaScript to current-EcmaScript compiler. It doesn’t add anything to the language that isn’t already proposed for the next version of EcmaScript.

If you just want to write EcmaScript 6 today, use Traceur. If you want optional strict typing and all the benefits that go along with that, plus some ES6 features, use TypeScript.

C Snover
  • 17,908
  • 5
  • 29
  • 39
  • 1
    I see your point, but i'm not sure I would say they are entirely different goals. One of the primary goals of both is to make large-scale application development easier for developers. Not to oversimplify, but TypeScript is of the opinion that a strong type system is an essential component of that, whereas ES6 looks at a more holistic view of the future of the language. – zumalifeguard May 15 '14 at 17:04
  • In contrast, Traceur is a future-EcmaScript to current-EcmaScript compiler. It doesn’t add anything to the language that isn’t already proposed for the next version of EcmaScript. Except it does… https://github.com/google/traceur-compiler/wiki/LanguageFeatures – Clintm Oct 10 '14 at 13:23
  • @Clintm The objective of Traceur, from the project itself, is “a JavaScript.next-to-JavaScript-of-today compiler”. With the exception of the Annotations proposal, everything else Traceur does was proposed for Harmony and is either in an ES spec or is a Harmony strawman, so this answer *is* accurate according to the stated goals of each project. One exception doesn’t invalidate the larger overarching goal. – C Snover Oct 17 '14 at 03:37
9

FYI the next version (2.0) of typescript in development is focused on ES6 compatibility : http://typescript.codeplex.com/wikipage?title=Roadmap

Updated post here:

http://blogs.msdn.com/b/typescript/archive/2014/10/22/typescript-and-the-road-to-2-0.aspx

From TypeScript 1.5 to TypeScript 2.0

As we look to the 2.0 release, we 're focusing on two goals in addition to our main goal of bringing good tooling to JavaScript development. The first is to align with ES6. Aligning with ES6 allows TypeScript to become a superset of the next JavaScript, opening the way for working with new code patterns like destructuring, string templates, promises, iterators and more in addition to features TypeScript already supports, such as classes and lambda functions. We're also working with the Flow and Angular teams to make sure that TypeScript is the best language for working with a broader range of libraries, including declarative frameworks like the upcoming Angular 2.0 release.

John
  • 6,503
  • 3
  • 37
  • 58
basarat
  • 261,912
  • 58
  • 460
  • 511
  • 1
    Yeah I'm back on the TS bandwagon, particularly because of the quality of the generated code. – Nikos Aug 08 '14 at 14:25
  • That roadmap is six months old, and it uses the phrase "align with ES6", which unless someone has more specific information, is so vague as to be meaningless. –  Oct 04 '14 at 12:26
  • @torazaburo well it was also 6 months ago when it was posted ;), I just updated it with a blog from the other day (10/22) – John Oct 25 '14 at 01:44
  • Psst, http://stackoverflow.com/review/suggested-edits/6075577 might be a good edit for you to incorporate into your answer. –  Oct 29 '14 at 20:19
0

I would definitely recommend going the ES6 route.

For anyone else landing on this question, go and check out tagtree's videos on ES6 features.

To see template strings, arrow syntax and desctructuring, have a look at this free tagtree tutorial screencast, no registration is required.

hendrikswan
  • 2,263
  • 1
  • 20
  • 25
0

for a large scale system I would definitely recommend going with typescript.

when u have a team working together typescript will give you all the benefits of modern computer language with es6 compatibility(based on microsoft roadmap) but with the strict typing and code completion benefits.

Nati Krisi
  • 1,023
  • 1
  • 12
  • 23
  • 1
    r u sure u know typescript at all?Take a look at typescript roadmap : https://typescript.codeplex.com/wikipage?title=Roadmap - Align with ECMAScript 6 – Nati Krisi Oct 05 '14 at 09:31
  • 2
    You said "give you", not "will give you" at some undefined point in the future to some unknown degree. No one even knows what "align" means, although it surely does not mean "fully compatible", not least because there are aspects to TypeScript that can never be made fully compatible. –  Oct 05 '14 at 10:53
  • 3
    It's not a matter of me being happy, it's a matter of SO readers getting accurate information. TypeScript has NEVER said it intends to be compatible with ES6, and as I mentioned there are structural reasons why it **cannot** be, without changing its basic nature. Hence, it is factually **incorrect** to say that choosing TS will give you ES6 compatibility. **it wont't**. The phrase "align with ES6" in the roadmap is best interpreted as meaning, "Adopt some ideas from ES6 where feasible, like comprehensions and string templates, and maybe/possibly tweak module syntax to look more like ES6." –  Oct 05 '14 at 12:56
0

Both Traceur and Typescript transpiles have very similar features, with some pros and cons.

I believe that the main questions to be answered, analyzed and compared more deeply are: "Who are its proponents?" and "What is the historic of every one of them?".

Q1: Well, both are big and reputable companies with large investment in technology, workforce to give future to their transpiles. Google is behind the Traceur and Microsoft is behind Typescript.

Q2.1: Google has a history as a strong supporter of open source frameworks such as Chromium (the open source browser base of Google Chrome) and thousands of free APIs available, almost all based on open standards. The Traceur follows this same logic adopting guidelines of ECMAScript 6 specification, anticipating it and ensuring its compatibility in future revisions.

Q2.2: Microsoft has a history of encompass standards and extend them proprietary, creating dependence on customers in their platform and not respecting a shared vision of standardization of other market players. The main objective of Typescript is compatibilize the other compilers on the market with the syntax and features of your JScript.NET compiler, not with the ECMAScript 6. Any mention of ECMA is just "sugar for ants".

The realtime typed parsing and the advanced code completion of Typescript are a considerable advantage for small projects, but larger projects need to take a right decision during the architecture definition, otherwise the entire project could be compromised by a compiler outdated or discontinued and out of standards, depending on an unique vendor.

However, many features of ECMAScript 6 are just implemented on the Firefox 33 and Chrome 38 current versions (in 2014-10).

http://kangax.github.io/compat-table/es6/

  • I am certainly not a fan of Microsoft (in fact, I work for its competitor), but I think this comparison is not fair for many reasons. First of all inputing bad intentions to Microsoft and good to Google stands against the current situation, when the latter is turning quite swiftly towards proprietary (many of those mentioned open APIs are deprecated now) and the former towards open. On the other hand, it is not fair comparing Traceur and TypeScript, because Traceur doesn't support yet another version of proprietary langauge, but coming standard ES6 (& there are other transpillers, e.g. Babel). – mcepl May 03 '15 at 22:50