-
Notifications
You must be signed in to change notification settings - Fork 742
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
[Bug] Return Type of Methods #368
Comments
The hard-coded return type "BigNumber" prevents subclasses from working correctly with TypeScript types when super class methods are called. See MikeMcl#368, this PR closes MikeMcl#368
After working for a while, I realized the problem was deeper than I thought. The code contains 56 hard-coded ```class ExtendedNumber extends BigNumber {
bar(): this {
return this.add(1).decimalPlaces(2);ts(2339)
}
}
let value = new ExtendedNumber("10.1"); // value is instance of ExtendedNumber
value = value.bar(); // value is instance of BigNumber !!!!! I tried to replace all Unfortunately, when I changed In the current situation, BigNumber.js seems hard to extend in a subclass. I'll be happy if you can change that, but it may need much more effort than you want to spend. Nonetheless, this is a very good library. Kind regards, |
Hi! Pretty much every method you call on an instance of BigNumber (e.g. So the return type of a method is actually never If you really want to do return bar(x: number) {
const c = new ExtendedNumber(this.plus(x));
const d = c.foo();
return this;
} I would strongly discourage this though, it's way easier to overlook something and write buggy code this way. It might seem like constantly creating instances is a waste of memory and CPU cycles, but:
|
Hi,
Thanks for this great library.
I'm developing a subclass by extending
BigNumber
to add my custom utility methods. However, when I tried to access superclass methods, I got type errors from TypeScript. (The code works as expected; I just got TypeScript typing errors).The problem is that the return type of methods is hard-coded as
BigNumber
. They should bethis
instead ofBigNumber
.For example see the original code from
bignumber.d.ts
file below:It should be:
Kind Regards,
The text was updated successfully, but these errors were encountered: