Converts TypeScript definition files (d.ts) to haxe externs
npm install dts2hxCommand-line tool to convert TypeScript type definitions to haxe externs

Thanks to the Haxe Foundation for supporting this project!
npm install dts2hx --save-dev
- Install a module with types, for example npm install three. If your module of choice doesn't include type definitions, try installing externally maintained ones with npm install @types/{module-name}
- Run dts2hx on the node module
npx dts2hx three --modular
This will generate externs into .haxelib/three, to use the externs, add --library three to your build.hxml file.
We add --modular because we intend to use the library via require() rather than via a global-scope THREE object. If you want to use the THREE object, add --global
- Alternatively, generate externs for all local package.json dependencies with
npx dts2hx --all
- For bonus points, add dts2hx as a postinstall script in your package.json so that externs are generated automatically after npm install
``json`
"scripts": {
"postinstall": "dts2hx --all"
}
See examples/ for example projects using popular js libraries
The generated externs use haxe 4+ syntax. See dts2hx --help for a complete list of options
- There are no TypeScript definitions for my module
Many popular js modules have external type definitions maintained in places like DefinitelyTyped – try installing external definitions with: npm install @types/{module-name}, then use dts2hx {module-name} as normal
- My types use TypeScript 4.0+ syntax and are not supported
While you're waiting for dts2hx to support newer syntax natively, you can use downlevel-dts to translate your types to TS 3.4 syntax which dts2hx will support
- How do you convert a local TypeScript definition file, like index.d.ts?
dts2hx uses the same module resolution as TypeScript, so in TypeScript you import types from this file with import {...} from './index', for dts2hx you would do dts2hx ./index
- Why is there a global package?
TypeScript definitions often define two parallel sets of types, one for use with