I have been using Open FL API till now. Just looked into the typescript section. Was intrigued to know if there are more benefits of using Typescript above Open FL API. Of course it’s easy for a typescript programmer to port flash. But are there additional benefits?
Haxe and TypeScript have similar goals (when we consider the web) but solve these problems from two different directions. Since both bring types to the web they share similarities, but each approach also comes with trade-offs.
TypeScript
TypeScript is a layer over vanilla ES5/ES6 JavaScript for better development experience. Integration of TypeScript can be done only in increments if desired. You can begin with a large JavaScript codebase and add an amount of type safety on the top, but all the usual quirks of JavaScript still apply.
TypeScript is simple to include using NPM and integrates with any JavaScript library in existence. Using untyped code and applying types to code is pretty easy, but obviously the result is web-only.
Haxe
Fortunately it is possible to include Haxe in a project using NPM nowadays, which helps. Other than the obvious benefits of Haxe as a cross-platform compiler (to bring code beyond the JavaScript runtime to new targets like Web Assembly or other platforms) the philosophy of Haxe also “reforms” the quirks of JavaScript. This makes it difficult to integrate with certain JavaScript libraries, but is a trade-off that may improve your experience as a developer when writing your own code.
Haxe supports untyped JavaScript and extern classes, but is limited when working with some JavaScript patterns and does not integrate as tightly with the JavaScript developer experience. It is harder to migrate from JavaScript to Haxe incrementally.
try.openfl.org
We have code sandbox available for trying OpenFL in the web browser using ES6 JavaScript.
It is possible to simulate TypeScript support in the same environment, but Haxe support strictly requires the Haxe compiler and is not available outside of running a virtual machine to execute the compiler.
Inversion of control
TypeScript starts with JavaScript and reaches toward type safety and better development for structured code. Haxe starts with cross-platform code and reaches toward JavaScript. There is a pretty good amount of overlap in the middle but there may be different compromises on the edges.
There are simple little differences we could identify as well, such as Haxe supporting Int
and Float
while TypeScript supports only Number
. In JavaScript there is no distinction between integer and floating point types but in Haxe there is such a distinction. This is hugely valuable when porting to native platforms but less important when executing in a runtime. Which is right? Which is better?
Anecdotally I would consider using JavaScript -> TypeScript -> Haxe (in that order) when developing a website, but would consider Haxe -> TypeScript -> JavaScript when developing an application or game.
The embedded examples of OpenFL on the openfl.org website are all written using ES5 JavaScript, but I would have preferred TypeScript.
Nearly every OpenFL sample is written in Haxe. Among other reasons, you do not need to write this.
all the time