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

Child class extending BN, using BN in constructor #206

Open
amaury1093 opened this issue Nov 13, 2018 · 1 comment
Open

Child class extending BN, using BN in constructor #206

amaury1093 opened this issue Nov 13, 2018 · 1 comment

Comments

@amaury1093
Copy link

amaury1093 commented Nov 13, 2018

import BN from "bn.js";

class MyBN extends BN {
  doSomething() {
    console.log("HELLO");
  }
}

const a = new MyBN(new BN(123));
console.log(a.toString());  // this works, logs 123
a.doSomething();

Expected:
Logs HELLO

Actual:
Doesn't log anything on the doSomething line.

Repro:
https://codesandbox.io/s/508mm5zz5l

Notes:
Using typescript 3.0.1

@fanatid
Copy link
Collaborator

fanatid commented Nov 13, 2018

I think this is expected result, check constructor function:

bn.js/lib/bn.js

Lines 22 to 24 in 24cc2dd

if (BN.isBN(number)) {
return number;
}

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

No branches or pull requests

3 participants