DEV Community

Discussion on: TypeScript Introduction - The Basics

Collapse
 
eljayadobe profile image
Eljay-Adobe

Nice rundown of TypeScript!

I think it is also worth pointing out that TypeScript is a superset of JavaScript. That means that if you cut-n-paste a chunk of JavaScript code into a *.ts file it is valid TypeScript too.

The killer feature that TypeScript brings to the table is all that type information -- whether explicit or implicit -- allows for a thorough static analysis for type checking.

For small JavaScript programs, that type checking is not a big value. But for larger web application programs, that type checking becomes invaluable. It eliminates an otherwise very error prone part of JavaScript, especially for larger programs.

Another killer feature of TypeScript -- which probably is less killer now that ES6 has been out for several years -- was that TypeScript brought ES6 functionality to ES3 and ES5. A sort of "polyfill" for the language syntax, handled by the compiler (also called the transpiler).

The third killer feature of TypeScript is that it provides a simple syntax that compiles into idiomatic and correct JavaScript. One of the systemic problems with JavaScript is that developers don't always cross all the ts and dot all the is for all the boilerplate code. TypeScript never falters on making all the correct boilerplate.

What's the cutoff? I think any JavaScript code that is more than a hundred lines long can greatly benefit by making it TypeScript, and annotating the type information or rely on the type inference.

How does it stack up to the competition? Elm, CoffeeScript, CoffeeScript 2, GorillaScript...? Others...?

TypeScript is a superset of JavaScript. So if you are an ES6 guru, you'll find TypeScript to be ES6 with a delicious sprinkling of type annotation.

Those other languages which compile to JavaScript are, themselves, not JavaScript. But you often need to be very aware of JavaScript peculiarities, in order not to make silly mistakes.

Elm is a function-first functional programming language. If you like Haskell or OCaml or F#, you'll probably be very happy with Elm. The downside to Elm is that it is undergoing tremendous growth (and churn) as the language evolves, so be prepared to be on the bleeding edge.

CoffeeScript and CoffeeScript 2 does for JavaScript what Groovy and Kotlin do for JVM, and what Boo! does for .NET (although Boo! hasn't caught on like Groovy or Kotlin). They are a kinder, gentler, friendlier, expressive language that compile to JavaScript. CoffeeScript does not compile to ES6. CoffeeScript 2 adds constructs to target ES6, and compiles to ES6. However, CoffeeScript 2 has a few "gotchas" for some ES6-isms, which hopefully will improve over time. What CoffeeScript and CoffeeScript 2 do not do is provide the static analysis facility that TypeScript provides.

GorillaScript... lol. I had to throw it out there, because GorillaScript is an abandoned effort, but one that I had tracked with high hopes. It was a better CoffeeScript than CoffeeScript. Alas, it isn't an ongoing thing anymore.

I think it would be so cool if CoffeeScript 2's syntactical succinct sweetness was somehow combined with TypeScript's type inference & explicit typing, static analysis, and boilerplate magic.

I used TypeScript 0.8 (and a version before that) from 2012 to 2014. That version did not have type union, and we felt the pain of not having that. It's nice to see that has been added! The other enhancements to TypeScript also look very nice.