Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluebird.hx type error chaining * -> Void functions with .then() #75

Open
laurence-myers opened this issue Oct 26, 2015 · 2 comments
Open

Comments

@laurence-myers
Copy link

I'm having trouble chaining functions/promises using the Bluebird extern. I believe Haxe's type inference engine is failing to deduce the return type of a fulfilledHandler that comes after a fulfilledHandler with a return type of Void.

Here's a small test case that exhibits the problem:

import buddy.BuddySuite;
import js.npm.Bluebird;
using buddy.Should;

class TestBluebird extends BuddySuite {
    public function new() {

        describe("Testing Bluebird", function () {
            it("Allows chaining after a '* -> Void' function", function (done) {
                var p = new Bluebird(function (resolve, reject) {
                    resolve("first value");
                }).then(function (firstValue) {
                    firstValue.should.be("first value");
                }).then(function () {
                    done();
                });
            });
        });
    }
}

I think I can work around the issue by returning "null" in one function and accepting a dummy arg in the next, but this is awkward for chaining existing functions together, and problematic for making use of externs or libs.

@clemos
Copy link
Owner

clemos commented Oct 26, 2015

Can you please make a PR with your test in https://github.com/clemos/haxe-js-kit/tree/master/test/buddy/src ?
It's indeed always difficult to keep JS's flexibility while typing stuff as much as possible, especially with method signatures / optional arguments.
Regarding the extern, you try to change T -> Tx signatures to ?T -> Tx (or ?T -> ?Tx ?); otherwise, you'll probably need to add more @:overload with Void -> Tx and/or Void -> Void ?

@laurence-myers
Copy link
Author

Yes, I'm finding it's quite difficult. If I use something simple like the "Promise.hx" stub contained in the Sequelize dir, that makes use of Dynamic, it works pretty well but loses type safety.

I had no idea you could have optional type parameters! That's amazing! 😄

I'm still learning Haxe, so apologies if I'm just doing something silly and not understanding how to enforce the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants