webidl-dts-gen
is a Web IDL to d.ts converter
This tool generates a TypeScript file based on a WebIDL input file.
This is a fork of webidl-dts-gen. Thank you for your work!
npm install webidl-dts-gen
Usage: webidl-dts-gen [options]
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]
-i, --in Input file or url [required]
-o, --out Output file path [required]
-f, --format Output format [dts/ts]
Generate type definitions from a local idl file:
webidl-dts-gen -i my.idl -o index.d.ts -f dts
Use remote IDL files:
webidl-dts-gen -i https://www.khronos.org/registry/webgl/specs/latest/2.0/webgl2.idl -o webgl.d.ts -f dts
Generate type definitions from online documentation:
webidl-dts-gen -i https://www.w3.org/TR/webxr/ -o webxr.d.ts -f dts
This is an excerpt of a package.json
with scripts to generate type definitions for the Ammojs project.
{
"scripts": {
"generate": "yarn generate:module && yarn generate:ambient",
"generate:module": "webidl-dts-gen -i ./ammo.idl -n Ammo -ed -o ./builds/ammo.d.ts -f dts",
"generate:ambient": "webidl-dts-gen -i ./ammo.idl -n Ammo -e -o ./builds/ammo-ambient.d.ts -f dts"
}
}
And an excerpt of the project structure in this scenario would be
├── builds/ // build output folder
│ ├── ammo.d.ts // The generated d.ts file with a default export
│ ├── ammo-ambient.d.ts // The generated d.ts file with ambient declarations only
├── ammo.idl // The idl file
├── package.json // The package file