Dts2hx update: TypeScript 6.0, Haxe 4.3, and much improved type conversion

Hi all,

dts2hx has been updated to work with TypeScript 6.0 (was 3.7) and Haxe 4.3

A bunch of type conversion issues have been fixed along the way — template literal types, NoInfer, bigint, never, Readonly producing final fields, index signatures on interfaces actually producing DynamicAccess

There’s also now an e2e test suite that does the full loop: TypeScript → JS + .d.ts → dts2hx → Haxe → JS → run against the original JS.

dts2hx also supports the new @:js.import metadata in Haxe nightly, so you can use ES module imports directly — no bundler needed for libraries like three.js that dropped CommonJS support.

PR: Support TypeScript 5, Haxe 5, and modern JS ecosystem by haxiomic · Pull Request #131 · haxiomic/dts2hx · GitHub

Here’s a worked example using three.js 0.182:

mkdir my-project && cd my-project

npm init -y
npm install three@0.182 @types/three@0.182
npm install --save-dev dts2hx esbuild

npx dts2hx three --modular

Write Main.hx:

import three.*;

function main() {
    var scene = new Scene();
    var camera = new PerspectiveCamera(75, 1.0, 0.1, 1000);
    camera.position.z = 3;

    var geometry = new BoxGeometry(1, 1, 1);
    var material = new MeshNormalMaterial();
    var cube = new Mesh(geometry, material);
    scene.add(cube);

    var renderer = new WebGLRenderer();
    renderer.setSize(800, 600);
    js.Browser.document.body.appendChild(renderer.domElement);

    renderer.setAnimationLoop((time, frame) -> {
        cube.rotation.x += 0.01;
        cube.rotation.y += 0.01;
        renderer.render(scene, camera);
    });
}

Write build.hxml:

-lib three
-main Main
-js dist/main.js
-dce full
-cmd npx esbuild dist/main.js --bundle --outfile=dist/bundle.js

Build and open:

haxe build.hxml
open index.html
3 Likes