Jump to content

Typescript vs Javascript


Recommended Posts

Hello everyone,

I've decided to start with PhaserJs, at the getting started page there is a sentence that reads "If you're coming from Flash / AS3 then we'd recommend giving a TypeScript a go"...

And yes I coming pretty much from 12 years of Flash.

Someone please could explain my what are the advantage of code in TypeScript and also recommend a IDE?

Thanks in advance



Link to comment
Share on other sites

There are quite a few threads on TypeScript adoption, have a search through for some fairly detailed discussions of pros/cons.

The very very very short (not putting them as pros/cons as some could be pros or could be cons depending on your point of view):


* Won the browser war, browsers don't run anything else so whatever you write your source code in, it'll need to be JS by the time it hits your platform (i.e. the browser, or browser-like environment such as Electron or Cordova).

* A very permissive language capable of making a good stab at a number of different coding styles

* A growing language, due to great support JS regularly adds new stuff to the language (some of the recent new stuff has come from subsets like Typescript and Coffeescript)

* JS runs in a browser, browsers implement JS engines sometimes differently, leading to unexpected results. Not really a language problem, but something to be aware of. If you transpile your code (i.e. write source in Typescript but compile it to JS) then this can sometimes round off the nasty edges with browser incompatibilities, sometimes create more problems.

* JS is generally an easy language to pick up, some of its ease-of-use results in nasties and inconsistencies further down the line.

* Writing in the language that your program will be running in (i.e. vanilla JS) will always have less friction than requiring a transpilation step (i.e. Typescript -> JS)


* Adds rudimentary type support to JS, I say rudimentary because JS does not support types and so (if being absolutely brutal) its a massive hack. It does this via static analysis, although TS have recently added something to do this at runtime (during a dev build, it adds a big perf hit), other type systems (such as Flow) have had this capability for a long time. If you want to perform code branching based on types then TS isn't going to help, its just a checker.

* As a documentation tool it is useful, although your code will become more verbose, but, knowing expected types is useful (I say expected because JS can not enforce it), magic comments also get you there, but aren't as elegant.

* TS compiles back to JS so there should be no perf problems when it hits the browser, infact, the transpilation is so good there may be cases where it writes it better than you could (ditto for other top transpilers like Babel).

* Generally speaking working with types is slower for you as a developer, but as your product matures you may find some benefits later on if you have your typed all laid out

* TS has a typed get-out-of-jail-free card by using <any>, to ignore typing, try not to use this

* Using TS with external modules is not friction-less, infact, it can be a major pain in the butt

* TS will not (generally) catch any bugs, not tricky ones anyway, don't believe the hype, write unit tests if you value your sanity, TS can help pinpoint some common coding errors but it won't help eliminate anything non-trivial

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...