Haxe externs are a way for Haxe to know about types of methods and properties of external objects like Phaser.
Surprisingly generating them took me a week and not the expected hour or two. And they still aren’t perfect (and probably never will be).
Which is why Phaser offers TypeScript definition files, which were written manually. TypeScript definitions are the same thing as haxe externs, but for TypeScript. “Great,” I thought. Well, it is great that they exist. That’s for sure. But converting them to Haxe proved challenging for many reasons.
I wish I kept notes as I iteratively wrote the conversion code, but I went into it with “this will only take a short while” mindset. How wrong I was.
More Phaser related issues were repeating of properties in subclasses that are also in the superclass (with different comment on them too – so they are worth keeping).
How I ended up implementing it, is by taking advantage of TypeScript’s Compiler API to parse the definition files. With that I iteratively wrote code to process the AST tree and export Haxe externs files.
The end result is a pretty ugly code that can be found here.
But it works :)