I work with Angular 1 for years now, and I'm starting to learn how to use Angular 2 instead.
But before writing any line of code, I struggle to whether I have to use TypeScript or JavaScript.
Bonus question :
I don't know TypeScript but from the few pieces of code I have seen, it seems the major features are :
Type hinting
Prototype mechanisms hidden under a most common used Class syntax.
My first impressions after browsing the web :
Type Hinting :
I love type hinting, but I think it's a little overkill to use a new language just to add this feature and will produce more work for the devs to use libraries with loose type (from the docs, there is some ways to do this).
Class-based styntax :
What about the new class syntax (which is close to the ES6) ? The Prototypes are the most misunderstood feature of JavaScript but I think it's more important to understand how it works (to know what you really do) than simply put it aside.
ES5 is a Prototype-based programming language so why do you want to use a pseudo Class-based programming language, which will eventually produce prototypes ? It seems weird to me.
Code generation :
The last point is about code generator. I've already used code generator in other context, and I don't really like it : in most case, a human will produce a better written code (I have taken a look to the generated js : anonymous functions, anonymous function everywhere !) and more concise (when it comes to load the generated js files in the browser the size is important to reduce loading)
To conclude :
For instance I'm not really convinced of the interest to learn TypeScript instead of sticking to ES5 JavaScript. So I would like to have feedbacks from the community to know the advantages of using TypeScript.
Advantages of using TypeScript over JavaScriptTypeScript always points out the compilation errors at the time of development (pre-compilation). Because of this getting runtime errors is less likely, whereas JavaScript is an interpreted language. TypeScript supports static/strong typing.
Yes, you can.
I think the advantage of Typescript is the transpiler to Javascript. When there is a new feature in Javascript the transpiler is able to create better Javascript while my Typescript isn't changing.
What I also like about Typescript is the type checking itself. It already saved me from coding errors simply because the types didn't match, also typed arrays helped me to structure like:
let members: array<People>
.
It forces other coders to provide the right object type.
One could also argue native Javascript is the way to go since it removes the transpiling process and is native.
From the Angular quickstart:
Typescript
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
Javascript
function(app) {
app.AppComponent =
ng.core.Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
As the example above illustrates, I prefer Typescript since my code looks cleaner and therefore better to understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With