I've been using Ionic 2 and Angular 2 a lot recently, and honestly these frameworks are awesome.
I used to be a big fanboy of Ionic 1 and Angular 1 but I have now transitioned to the v2s and they are far superior.
Now there is only one thing which profoundly annoys me with Angular 2, and it is that I hate Typescript.
And to be clear, I know it is not politically correct to say this. I know Typescript is the new cool kid on the block and I know not falling in love with the new cool kid on the block is one the biggest mistakes you can do.
And to be clear, I know it is not politically correct to say this. I know Typescript is the new cool kid on the block and I know not falling in love with the new cool kid on the block is one the biggest mistakes you can do.
Typescript is actually better than Javascript
To be fair, Typescript is in fact a very amenable language. It is elegant, it is easy to learn, it has nice features. It feels modern. That's all very nice.
I don't really hate Typescript actually. I just want Javascript back.
I know this sounds silly. Javascript is best known for its awfully nested syntax, absurd type inconsistencies, broken scheme absence of scheme, inability to inherit... Javascript is a mess which keeps on telling me 'Undefined property'. And yes, it's undefined and that's because you, Javascript, are a mess.
this
keyword, ill-defined reference-passing
But Javascript doesn't need a compiler. Or a transpiler. Or a whatever-piler that wastes my time. Javascript is what it claims to be : a script.
The transpiler is slowly killing me
Let me talk about the Ionic 2 app I'm writing right now. On my MacBook, the build time takes 45 seconds. I also have an older PC under Linux, it takes 223 seconds. What's wrong with you Typescript ???
What's wrong is your transpiler. I want to be able to change the name of a variable without waiting 223 seconds. Or 45 seconds. Or even 1 second. I want to load in my browser instantly and launch the Chrome debugging console now.
That's right, 45 seconds. I changed the name of a variable. |
Not only the wait time is terrible, but Typescript makes the whole debugging process an absolute nightmare. If you have not been introduced to the concept of transpiled bundle yet, here it is : my app has only about 200 lines of code but my Ionic bundle has 80,000 lines.
Setting a simple breakpoint breaks the debugger, which stalls painfully trying to figure out the mappings, then redirects me inside some non-sense auto-generated gibberish.
Lines 5185-5190 : the only section in the bundle that actually makes sense to me |
Why do we use Typescript already ?
Here are my 2 cents about all the good reasons that we have to be using Typescript :
- Proper classes : ES6 has classes, we don't need Typescript for this.
- Promises everywhere : ES6 has promises, we don't need Typescript for this. Oh and yes, Observables. Of course we need them badly, because it's a good reason to add another 2000 lines of RxJS code into the bundle.
- Clean scope for
this
: Nobody has a clean scope forthis
. ES6 doesn't have one, Typescript doesn't have one either. Try writing a fat-arrow function in your supposedly clean Typescript class, and you will be thrown right back into Javascript hell. - Annotations : Who likes annotations anyway ? It is not proper code, it is not proper comment. If you really want your code to look like Javadoc, then use Babel.
- Dependency injection : OK, I'll be honest, annotations are extremely useful, especially for dependency injection. But Angular 1 had DI, and no annotations. Did it look ugly ? Yes it did, but no uglier than annotations in my opinion.
- Imports : Ah, imports. Yes, Typescript does this perfectly. But Angular 2 guys, please. Could you just not figure out a simple wrapper for this ?
I reckon this is more a prejudiced rant than a serious analysis of the merits of Typescript vs ES6. As I said, Typescript is truly a very nice language.
But I can't bear the transpile process anymore. If I want painful compilation and debugging, I can write proper native code in a full-blown IDE. The only reason why I use Ionic is because I can write a quick script in a simple text editor and deploy it immediately.
What I need
I'm not stupid, I will not suggest here to dump Typescript completely. I know the rules and I know it would be an insult to the God of Code, whose first commandment is "Thou shall never prefer an existing language over a new one", and whose second commandment is "Thou shall never admit that you use a language that has 'Java' in it".
Ultimately, I do not care about the language. I care about the workflow.
And to streamline the workflow I need to be able to write scripts that can be executed and debugged in the browser directly. Once the code is stable and can reach production status, then I will bundle it for distribution.
For this I would need a new browser engine that understands Typescript natively, so that I can bypass the transpilation step altogether. At least Chrome, ideally Safari also for us Mac developers who are testing against iOS.
The bad choice I made
Unfortunately this new browser doesn't exist. In the meantime, my choices are rather limited:
- I use Typescript despite its unbearably slow transpiler, and I accept a broken workflow
- I use Angular 2 with Javascript despite the absolute lack of any documentation, and I accept to be alone against the crowd on that path
- I use Angular 1 despite the fact that it is now in maintenance mode, and I accept to miss all the new cool features of Angular 2
For now, I have decided to go with solution 1.
In a nutshell, I had three bad options and I made a choice. Which, obviously, is bad.
Now you know why I hate Typescript.
A footnote
I cheated.
I confess.
Below the transpile time for the dev-build.
21 seconds, not 45 seconds. Hurray !!!!
I will probably change another variable name to celebrate.
Using the undocumented --dev option. What a great outcome !