Hey all!
For the last year I’ve been working on a tool to convert TypeScript definitions to haxe externs using the TypeScript compiler and now I think it’s complete enough to announce
How to use:
-
Install dts2hx from npm
npm install dts2hx --save-dev
-
Install a module with types, e.g.
npm install three
-
Run dts2hx on the node module
npx dts2hx three
-
Or alternatively, generate externs for all local package.json dependencies with
npx dts2hx --all
-
This will generate externs for haxe 4+ into a directory called .haxelib/, which is a local list of haxelib libraries, similar to node_modules for npm.
-
Then to use the three externs, add
--library three
to your build hxml
See the github repository (haxiomic/dts2hx) for more details
It should work well for most game libraries, I’ve created examples for babylonjs, phaser, pixi.js, playcanvas and three.js
While I expect it to do a good job on most TypeScript modules, modules which rely heavily on advanced TypeScript features like mapped types will lose some type information, so for libraries like React and vue.js you’d be better off using hand-curated externs like haxe-react
Please test it out on your favorite and TypeScript libraries and report any issues you find
Thanks to the Haxe Foundation for their support