Closed arcticmatt closed 2 years ago
Try this code:
const bn = new BN(5); const u = new u64(10); const u2 = new u64(bn); console.log("bn.toBuffer", bn.toBuffer); console.log("u.toBuffer", u.toBuffer); console.log("u2.toBuffer", u2.toBuffer);
Logging u.toBuffer shows a function. But logging u2.toBuffer shows undefined, even though toBuffer is defined right here! https://github.com/solana-labs/solana-program-library/blob/master/token/js/client/token.js#L54-L65
u.toBuffer
u2.toBuffer
toBuffer
Why? It's because of BN's constructor: https://github.com/indutny/bn.js/blob/master/lib/bn.js#L21-L24
BN
This behavior is very misleading in TypeScript, because u2 is typed as a u64, which you expect to have a toBuffer function.
u2
u64
In order to fix this, I think we should override BN's constructor in u64.
@joncinque gave this one a shot, could you take a look at #2975
This issue no longer applies -- @solana/spl-token uses native bigint.
@solana/spl-token
Try this code:
Logging
u.toBuffer
shows a function. But loggingu2.toBuffer
shows undefined, even thoughtoBuffer
is defined right here! https://github.com/solana-labs/solana-program-library/blob/master/token/js/client/token.js#L54-L65Why? It's because of
BN
's constructor: https://github.com/indutny/bn.js/blob/master/lib/bn.js#L21-L24This behavior is very misleading in TypeScript, because
u2
is typed as au64
, which you expect to have atoBuffer
function.In order to fix this, I think we should override
BN
's constructor inu64
.