Working with js.lib.Promise

There’s no utility to the argument there, it’s there because of a “limitation” of Haxe’s type system. There’s no way (as far as I know) to define a generic argument that may be Void (meaning that you can’t make a function that may or may not take an argument depending on it’s generic type).

So in Haxe you can’t really use Promise<Void>, instead you could use Promise<Dynamic> and ignore the argument in the then function.

Regarding the side question, keep in mind that the .then method returns a new promise that resolves to whatever the function you pass to it evaluates to. So you can use then to map a promise into a different type or even to chain promises.

If you are targetting just javascript and using promises I recommend you take a look at hx-jsasync (a lib I made and maintain)

1 Like