They didn't use JavaScript / TypeScript because of AOT requirements on iOS (Flutter actually was originally prototyped with JS as the language). Dart was mostly chosen for its runtime, which allows both Hot reload at dev time, as well as full AOT compilation to get native speed on iOS. React Native runs a JS interpreter to get around this on iOS and as a result is an order of magnitude+ slower
The speed is fixable. Performant AOT is very possible with Typescript. But if Facebook is not doing it, then the performance is good enough for them. Plus one can always code the problematic part in the native language.
Because TypeScript's type system is (by design and for good reason) unsound, an AOT compiler can't rely on static types to generate smaller more efficient code. It's always very hard to compile a dynamically typed language to fast code than it is a statically typed language.
Dart (as of 2.0) has a sound static type system. It's just an easier language compile well.
Even before that, Dart was easier to compile efficiently than JavaScript because classes are purely declarative and all objects have a fixed field layout.
Huh, which AOT compilers for JavaScript exist which achieve high performance? I thought JS as a language 100% depended on the runtime information available to a JIT for decent performance?
fpoling is referring to a _theoretical_ TypeScript compiler that doesn't actually exist in real life but could be written, that the Flutter team would apparently summon from the aether whole-cloth then proceed to maintain feature-for-feature parity with the official TypeScript compiler
Well, you wouldn't have to maintain feature parity with Microsoft's TS compiler. If you had some magical ES5 AOT compiler, you could just compile your TS to ES5 using the official TS compiler and then AOT-compile your ES5. No evolving spec to keep up with (at least as long as the upstream TS compiler maintains ES5 support). I'm really just curious about how one would AOT-compile a language as dynamic as JavaScript (be it TypeScript, ES3, ES5, or anything else) and achieve JIT-like performance.
Just to give a counterpoint to this, I love Dart. My preferred language is Ruby and Dart certainly is not Ruby. But it also makes me a bit happy when writing it: It's easy to understand and clean enough. The typing system is done well enough that it does not get in the way as much as early Java did. There were very few surprises with Dart. It has limitations (especially when trying to incorporate more functional patterns and felt when working with JSON), but I can work with that. Most of the time I can just write the code I want, organize it as I want and the Code will look as expected. No blockers there.
This is really some armchair psychoanalysis on my part, totally not worth anything in the way of intellectual attention, but I always found this interview with both Typescript and Dart leads to be interesting. https://youtu.be/5AqbCQuK0gM
I can't help but infer that Lars is quite often a little bit frustrated with the emergence of Typescript. But on top of it being embarrassing for me to imagine up such personal rivalries based on hardly anything, you could view the interview as Dart-hostile given the interviewer.
It felt like they couldn't use it for anything else so it was mandated that people use it somewhere.