You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let BN denote the class as exported from web3-utils, not bn.js.
Assigning results of BN methods, like add(), to variables of type BN should work.
Actual behavior
Doesn't compile, throws typescript errors.
Steps to reproduce the behavior with error logs
The code
import{BN}from"web3-utils";leta=toBN(0);// or new BN(0)letb: BN;b=a.add(toBN(1));
gives error
error TS2741: Property 'super' is missing in type 'BN' but required in type 'BN'.
71 b = a.add(toBN(1));
~
node_modules/web3-utils/types/index.d.ts:73:5
73 super(number: number | string | number[] | Buffer | BN, base?: number | 'hex', endian?: 'le' | 'be'): BigNumber;
~~~~~
'super' is declared here.
So right now I do arithmetics with a.add(toBN(1)) as BN hacks.
Now I could instead do import BN = require('bn.js'); but then I get another error when passing those BNs into, e.g., web3.utils.soliditySha3:
error TS2345: Argument of type 'BN' is not assignable to parameter of type 'Mixed'.
Property 'super' is missing in type 'BN' but required in type 'BN'.
Background
The web3-utils type declarations internally first do
importBigNumber= require('bn.js');
(which in itself is confusing, because bn.js is usually imported as BN and BigNumber is used for bignumber.js) and then declares and exports a wrapper class
Expected behavior
Let
BN
denote the class as exported fromweb3-utils
, notbn.js
.Assigning results of
BN
methods, likeadd()
, to variables of typeBN
should work.Actual behavior
Doesn't compile, throws typescript errors.
Steps to reproduce the behavior with error logs
The code
gives error
So right now I do arithmetics with
a.add(toBN(1)) as BN
hacks.Now I could instead do
import BN = require('bn.js');
but then I get another error when passing thoseBN
s into, e.g.,web3.utils.soliditySha3
:Background
The web3-utils type declarations internally first do
(which in itself is confusing, because
bn.js
is usually imported asBN
andBigNumber
is used forbignumber.js
) and then declares and exports a wrapper classWhy is that? Why doesn't web3 just use
bn.js
directly?This whole
BN
situation is a bit confusing, see also #2171Versions
Tested with node
v11.9.0
web3 version1.0.0-beta.43
and typescript3.3.1
in a trufflev5.0.2
project.The text was updated successfully, but these errors were encountered: