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

TypeError when constructing subclass of Promise #8474

Closed
chajath opened this issue Sep 10, 2016 · 3 comments
Closed

TypeError when constructing subclass of Promise #8474

chajath opened this issue Sep 10, 2016 · 3 comments
Labels
promises Issues and PRs related to ECMAScript promises. v8 engine Issues and PRs related to the V8 dependency.

Comments

@chajath
Copy link

chajath commented Sep 10, 2016

  • Version: 6.5.0
  • Platform: Linux
  • Subsystem: Promise

I'm writing a library that extends Promise class. In version 6.5.0, I've started to see the errors being thrown when trying to construct the subclass:

     TypeError: #<ChainedPromise> is not a promise
      at new ChainedPromise (src/ChainedPromise.js:68:72)

Here is the source code for ChainedPromise

@mscdex mscdex added promises Issues and PRs related to ECMAScript promises. v8 engine Issues and PRs related to the V8 dependency. labels Sep 10, 2016
@bnoordhuis
Copy link
Member

You're using import/export syntax so you must have a transpile step like babel. Can you post an example using just built-in syntax with no third-party dependencies?

@chajath
Copy link
Author

chajath commented Sep 10, 2016

Actually, when I test with vanilla node 6.5.0 code, it works as expected (as with previous versions)

"use strict";

class subPromise extends Promise {
  constructor(executor) {
    super(executor);
  }
}

const testPromise = new subPromise((resolve, reject) => {
  resolve(42);
});

testPromise.then(console.log);

Even with babel polyfill imported, it works fine. The problem is when I transpile with babel

# with es2015 preset
$ babel subPromise.js > subPromise.babel.js 
$ node subPromise.babel.js

    return _possibleConstructorReturn(this, (subPromise.__proto__ || Object.getPrototypeOf(subPromise)).call(this, executor));

        ^

TypeError: #<subPromise> is not a promise

Curiously this is only happening with 6.5.0 and not previous versions of node. I will also open an issue with babel and see what they think.

@chajath
Copy link
Author

chajath commented Sep 10, 2016

It was a known issue from babel when trying to extend built-in classes, with a plugin provided as a workaround. I guess the change was that from Node 6.5.0 Promise starts to behaves a lot more like a built-in class.

@chajath chajath closed this as completed Sep 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
promises Issues and PRs related to ECMAScript promises. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

3 participants