Layka

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

 

 

Share this post


Link to post
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):

Javascript:

* 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)

Typescript:

* 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.