diff --git a/packages/types-codec/package.json b/packages/types-codec/package.json index 59623f8afa..6a462800c5 100644 --- a/packages/types-codec/package.json +++ b/packages/types-codec/package.json @@ -24,7 +24,8 @@ "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.3", - "@polkadot/util": "^9.5.1" + "@polkadot/util": "^9.5.1", + "@polkadot/x-bigint": "^9.5.1" }, "devDependencies": { "@polkadot/types": "8.9.2-3", diff --git a/packages/types-codec/src/abstract/BigInt.ts b/packages/types-codec/src/abstract/BigInt.ts new file mode 100644 index 0000000000..a18f98399f --- /dev/null +++ b/packages/types-codec/src/abstract/BigInt.ts @@ -0,0 +1,16 @@ +// Copyright 2017-2022 @polkadot/types-codec authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { BigInt } from '@polkadot/x-bigint'; + +// @ts-expect-error not extensible, we make it extensible here +export abstract class AbstractBigInt extends BigInt { + // @ts-expect-error super() not required, the self magic does that + constructor (value: string | number | bigint | boolean) { + const self = Object(BigInt(value)) as typeof AbstractBigInt; + + Object.setPrototypeOf(self, AbstractBigInt.prototype); + + return self; + } +} diff --git a/yarn.lock b/yarn.lock index 59c5206dec..d9743456f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2257,6 +2257,7 @@ __metadata: "@polkadot/types-support": 8.9.2-3 "@polkadot/util": ^9.5.1 "@polkadot/util-crypto": ^9.5.1 + "@polkadot/x-bigint": ^9.5.1 languageName: unknown linkType: soft @@ -2422,7 +2423,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/x-bigint@npm:9.5.1": +"@polkadot/x-bigint@npm:9.5.1, @polkadot/x-bigint@npm:^9.5.1": version: 9.5.1 resolution: "@polkadot/x-bigint@npm:9.5.1" dependencies: