BowlerHatLLC / dts2as

Convert TypeScript definitions (d.ts files) into ActionScript classes and interfaces for use as external libraries with Apache FlexJS
https://www.npmjs.com/package/dts2as
Apache License 2.0
39 stars 4 forks source link
actionscript apache-flexjs flexjs nextgen-actionscript swc typescript typescript-definitions

dts2as

Note: This project is no longer under active development. Use at your own risk.

A command line utility that converts TypeScript definitions (d.ts files) to ActionScript classes and interfaces and generates a SWC file. Use these SWCs with Apache FlexJS for strict compile-time type checking, as if the JavaScript library were written in ActionScript. You can add the SWCs to IDEs, like Visual Studio Code, Flash Builder, or IntelliJ IDEA, and you'll get helpful code suggestions as you type.

Installation

Requires Node.js.

npm install -g dts2as

Usage

dts2as hello.d.ts
dts2as file1.d.ts file2.d.ts
dts2as --outSWC hello.swc hello.d.ts
dts2as --outDir ./as3-files file.d.ts
dts2as --exclude com.example.SomeType file.d.ts

The following arguments are available:

Using the SWC with Apache FlexJS

To use the generated SWC file with Apache FlexJS, you need to append it to the external library path.

If you're using the FlexJS framework components, you can compile with mxmlc:

mxmlc --external-library-path+=generated.swc src/MyProject.mxml

For pure ActionScript projects that target native JavaScript APIs, like the HTML DOM, you can compile with asjsc:

asjsc --external-library-path+=generated.swc src/MyProject.as

For more details, please check out the following tutorial:

Introduction to dts2as: Using TypeScript definitions with ActionScript

Troubleshooting

TypeScript definition files support a surprisingly large subset of the TypeScript language. Sometimes, dts2as won't know how to parse some of the more advanced syntax (although it's certainly getting better at it over time!). When dts2as runs into problems, it may not be able to compile a SWC file for you. You have a few options when dts2as fails:


Special thanks to the following sponsors for their generous support: