peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

BigInt constructor #207

Closed omatrot closed 4 years ago

omatrot commented 4 years ago

I know that bigInt is a function, but I would need to wrap it into something that could allow me to use bigInt with a constructor:

new (...args: any[]): any

How can I do that, knowing that I'm using TypeScript?

peterolson commented 4 years ago

Of course you can always create a constructor function wrapper:

function BigInteger(...args) {
    return bigInt(...args);
}

Then you can use new:

let x  = new BigInteger("hello", 36)

I'm not sure why exactly you would need to do this, though.

omatrot commented 4 years ago

Thanks for the input, I need this to use it in conjunction with a serialization library that uses annotations. So it appears it needs to be a class constructor...