MikeMcl / bignumber.js

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
http://mikemcl.github.io/bignumber.js
MIT License
6.65k stars 742 forks source link

Cannot create bignumber instance without `new` #251

Closed jurosh closed 2 years ago

jurosh commented 4 years ago

There is problem creating instance of bignumber in typescript (probably also in JavaScript)

import BigNumber from 'bignumber.js';
const bn = BigNumber('0.123');

There is error : Value of type 'typeof BigNumber' is not callable. Did you mean to include 'new'?

As per doc new keyword for creating instance of Bignumber should not be required.

djmattyg007 commented 4 years ago

Is there an issue with using new? It is meant to be used as a class after all.

MikeMcl commented 4 years ago

There is problem creating instance of bignumber in typescript (probably also in JavaScript)

No, it's just in typescript.

This stackoverflow post seems to give some workarounds but I am not going to try and fix this issue myself.

I recommend that typescript users just use new.

Of course, if someone wants to amend the bignumber.d.ts file to fix this issue then a PR wpuld be welcome.