This is great - I didn't know dts2as [1] was a thing.

I recently forked as3-to-typescript [2] which uses code ported to
TypeScript from FlexPMD [3], fixed all the bugs I could find, and made it
output just definitions rather than trying to generate all the AS code in
TS syntax. After hearing about dts2as I've renamed it to as2dts and
published it on npm [4]. This means TypeScript projects can now have strong
typing information for FlexJS libraries and vice versa.

I'm using as2dts in my own project [5] because we're writing all the GUI in
TypeScript/React (which I highly recommend looking into) but using an AS
core [6] via FlexJS and it would be a nightmare to develop things without
strong typing information.

An interesting note is that TypeScript allows templating like
Array<MyClass>, so I've added a way in as2dts to support that.  It handles
comments surrounded by /*/../*/ to denote TS typings and/or template info
inline in your AS code.  For example [7][8]:

public static function getDescendants/*/<T>/*/(object:ILinkableObject,
filter:/*/new(..._:any[])=>T | string/*/Class = null):Array/*/<T &
ILinkableObject>/*/

becomes

static getDescendants<T>(object: ILinkableObject, filter?: new (..._: any[])
=> T | string): Array<T & ILinkableObject>;

TS does type inference, so if you create a variable like this (using the AS
class Weave):
var result = Weave.getDescendants(root, MyClass);
the compiler will now know that result is of type MyClass[], without having
to specify it like var result:MyClass[].

[1] https://www.npmjs.com/package/dts2as
[2] https://github.com/fdecampredon/as3-to-typescript
[3]
https://github.com/apache/flex-utilities/tree/develop/FlexPMD/flex-pmd-java/as3-parser/src/main/java/de/bokelberg/flex/parser
[4] https://github.com/WeaveTeam/as2dts
[5] https://github.com/WeaveTeam/weave-html5
[6] https://github.com/WeaveTeam/Weave/tree/develop/WeaveJS
[7]
https://github.com/WeaveTeam/Weave/blob/0c163c1/WeaveJS/src/Weave.as#L270
[8]
https://github.com/WeaveTeam/weave-html5/blob/715072d/typings/weave/weavejs.d.ts#L116

On Mon, Mar 14, 2016 at 11:19 AM, Michael Schmalle <
teotigraphix...@gmail.com> wrote:

> On Mon, Mar 14, 2016 at 11:09 AM, Josh Tynjala <joshtynj...@gmail.com>
> wrote:
>
> > dts2as pretty much does the same job as externc, except it uses
> TypeScript
> > definitions instead of JS externs. So yes, it probably could replace
> > externc.
> >
> > One thing to keep in mind is that dts2as requires Node.js. Everything in
> > the SDK currently uses Java, as far as I know. Requiring another runtime
> > will make it more challenging to build everything.
> >
>
> Ok, well then that meas node js needs to be installed on the build computer
> correct?
>
> It just seems to me that if this project gets more traction, using the huge
> TS definitions seems like a win and you are developing the dts2as right
> now.
>
> Oh well, just a question.
>
> Chris I know what you mean about the Java relm but when I created EXTERNC
> it was to get Alex and Peter out of handwritting js.
>
> That said, there is only "so much" that compiler can do because I hacked it
> together in about a month. Thinking about a way to create something that
> can support a yriad amount of definitions that are supported by the current
> TS community is definitely something to think about.
>
> Mike
>

Reply via email to